Problem with Class scope resolution

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!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
//**********Class Definitions/Function Prototypes**********
class List
{
    public:
        //Typedef declarations
        typedef char ET;//Element Type
        static const 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();
        bool operator==(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)
    {
        return false;
    }
    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++;

        return true;
    }
}

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
Your class List has no such member as myStack. So it is not clear why are you trying access myStack in List's member function definitions. For example

1
2
3
4
5
void List::push(int value)
{
    Stack::myStack.end();
    Stack::myStack.InsertAfter(value));
}
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.
Topic archived. No new replies allowed.