I have a List class and I am to now add a stack class and use some of the functions from the list class. I put everything together, but I am getting an error that I believe has something to do with the scope of the two classes. Currently there isn't anything in the main because I can't get it to compile without errors. I have included a sample of the errors. The same errors repeat for each instance. I greatly appreciate any comments, hints, or tips provided!
//**********Class Definitions/Function Prototypes**********
class List
{
public:
//Typedef declarations
typedefchar ET;//Element Type
staticconst ET CAPACITY = 20; //Size of the array
//Constructor
List();
//Class Member Functions
bool empty();
void front();
void end();
bool insertAfter(ET);
int getElement();
int size();
void erase();
booloperator==(List &);
void push(int);
void pop();
ET top();
void full();
//Friends
friend ostream &operator<<(ostream &out, const List &l);
private:
ET MyAry[CAPACITY];
int Position; //Points current position
int Used; //Points to next available position
};
class Stack
{
public:
//Stack();
private:
List myStack;
};
//Operator Overloads
List operator+(const List &a, const List &b);
int main()
{
}
//**********Function Definitions**********
List::List()
{
//Set to zero
Position = 0;
Used = 0;
//Zero out array
for(int i = 0; i < CAPACITY; i++)
{
MyAry[i] = 0;
}
}
bool List::empty()
{
//Used = 0 is returns true
return Used;
}
void List::front()
{
//Sets position to the first location
Position = 0;
}
void List::end()
{
//Gets the end position
if(Used != 0)
{
Position = Used - 1;
}
}
bool List::insertAfter(ET value)
{
//Checks for position out of bounds
if(Position + 1 > CAPACITY)
{
returnfalse;
}
else
{
//If used is zero then first element
if(Used == 0)
{
MyAry[Used] = value;
}
else
{
//Moves everything down to make room for new element
for(int i = Used; i > Position + 1; i--)
{
MyAry[i] = MyAry[i - 1];
}
MyAry[Position] = value;
}
//Increment
Position++;
Used++;
returntrue;
}
}
int List::getElement()
{
//Returns element at Position
return Position;
}
int List::size()
{
//Returns size of the array
return Used;
}
void List::erase()
{
//Move all remaining elements down
for(int i = Position; i < Used; i++)
{
MyAry[i] = MyAry[i + 1];
}
//Decrement Used
Used--;
}
ostream &operator<<(ostream &outs, const List &s)
{
for(int i = 0; i < s.Used; i++)
{
outs << s.MyAry[i] << " ";
}
return outs;
}
bool List::operator ==(List &l)
{
if(Used == l.size()
&&
MyAry[0]==l.MyAry[0]
&&
MyAry[(Used-1)]==l.MyAry[(Used-1)])
{return 1;}
else
{return 0;}
}
List operator +(const List &L1, const List &L2)
{
List answer;
answer = L1 + L2;
return answer;
}
void List::push(int value)
{
Stack::myStack.end();
Stack::myStack.InsertAfter(value));
}
void List::pop()
{
Stack::myStack.end();
Stack::myStack.erase();
}
ET List::top()
{
Stack::myStack.end();
Stack::myStack.getElement();
return;
}
error: 'List Stack::myStack' is private
error: void List::push(int value)- within this context
error: object missing in reference to 'Stack::myStack'
error: from this location
The instructions were to create a Stack class to go along with the list class we already had. Inside the stack class I was to create a private variable called:
List myStack which was according to my understanding, give myStack access to the functions in List.