I'm having issues with this code for a bag ADT. I'm using a a pointer array made of a separate class that stores a string and an int.
ArrayBag::ArrayBag(int length){
list = new ReceiptArray [length];
size = length;
n= 0;
}
int ArrayBag::getCurrentSize(){return n;};
bool ArrayBag::isEmpty() {
if (!(n==0)){
return 1;
cout << "has items"<< endl;
}
else{
cout << "empty" << endl;
return 0;
}
}
bool ArrayBag::add(string item){
if (!(n==size)){
(*list+n.item) = item;
(*list+n.itemnum) = n+1;
it is the pointer arithmetic lines above that are proving difficult
n++;
return 1;
}
else{
cout << "bag full" << endl;
return 0;}
}
bool ArrayBag::remove(string item){
for(int k=0;k<n;k++){
Here too
if ((*list+k.item) == item){
(*list+k.item) = (*list+n.item);
n--;
return true;
}
}
return false;
}
void ArrayBag::clear(){n=0;}
int ArrayBag::getFrequencyOf(string item){
int frequency = 0;
for(int k=0;k<n;k++){
if(*list+k.item == item){
++frequency;}
}
return frequency;
}
bool ArrayBag::contains(string item){
for(int k=0;k<n;k++){
if(*list+k.item == item){
return 1;
}
}
return 0;
}
The errors
error: request for member ‘item’ in ‘((ArrayBag*)this)->ArrayBag::n’, which is of non-class type ‘int’
(*list+n.item) = item;
I'm confused on why this is happening. I thought you could index the pointer array this way. It happens anywhere where I try to add the current size of the array to properly index the array and access the arrays member variables. Any advice is welcome