I have below a header file for a stack structure. what I don’t understand is this error it is jamming at me:
ISO C++ forbids declaration of ‘Stack’ with no type
Here’s the code :
#include <stdexcept>
class Element;
class Stack{
public:
Stack():first(0){}; //constructor
~Stack(); //destructor
void push(int d);
int pop()throw(length_error);
bool empty();
private:
Element *first;
Stack(const& Stack){}; //copy constructor
Stack& operator = (const& Stack){}; //assignment operator..
};
does anyone have a clue what the error means?
Stack& operator = (const& Stack)should beStack& operator = (const Stack&).You can’t have a pointer to a reference or an array of references or anything so the compiler thinks that
&must end the type part of the declaration and that the followingStackmust be the parameter name. However there’s no type inconst&so the compiler says that you can’t declare the parameterStackwith no type. In old versions of C the typeintwas sometimes inferred in contexts where a type could appear but was omitted which is why the error talks about ISO C++ forbidding this.