Thanks for that tip. Can you tell why I get following error
stack.c++:11: error: ISO C++ forbids declaration of ‘Element’ with no type
stack.c++:11: error: expected ‘;’ before ‘*’ token
stack.c++:62: error: no ‘Stack::Element* Stack::findMToLastElement(int)’ member function declared in class ‘Stack
when I use Stack as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class Stack
{
public:
Stack();
~Stack();
void push(void *data);
void *pop();
Element * findMToLastElement(int m);
private:
struct Element
{
struct Element *next;
void *data;
};
Element *head;
};
Is it a must to declare the data members before using it, as I did on the first post?