1

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?

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
helpdesk
  • 1,984
  • 6
  • 32
  • 50

1 Answers1

9

Stack& operator = (const& Stack) should be Stack& 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 following Stack must be the parameter name. However there's no type in const& so the compiler says that you can't declare the parameter Stack with no type. In old versions of C the type int was sometimes inferred in contexts where a type could appear but was omitted which is why the error talks about ISO C++ forbidding this.

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
  • could there be something wrong with the int pop()throw(length_error) because, i also get the error : "expected type-specifier before 'length-errror' " ? – helpdesk Nov 26 '11 at 00:02
  • 3
    @henryjoseph: I assume you mean `length_error`. `length_error` is in the std namespaces so you need `throw(std::length_error)` although I recommend avoiding dynamic exception specifications like this. They are deprecated. – CB Bailey Nov 26 '11 at 00:04