简体   繁体   中英

ISO C++ forbids declaration of 'Stack' with no type

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 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM