Error: expected class-name before

1

I'm developing a project where I have an online class that inherits from an X class, where this X class needs to give a new in an online class object. When I do this happens the error, due to the inheritance I believe:

  

expected class-name before

class X
{
    public:
        X();
        virtual ~X();
        X* makeMethod(string Method);
    protected:

    private:
};

X* X::makeMethod(string Method){
    return new online();
}

class online: public X{
    public:
        online();
        virtual ~online();
        void makeMethod(string Method);
    protected:

    private: };

How do I resolve this error?

    
asked by anonymous 08.10.2018 / 03:11

1 answer

0

Declare the class before setting it, it may even be the first line of the file:

class online {};

So you can already use it in your code and only then define how it will be implemented, as it already did, which can be after it has already been used.

class online {};

class X {
    public:
        X();
        virtual ~X();
        X* makeMethod(string Method);
};

X* X::makeMethod(string Method) {
    return new online();
}

class online: public X {
    public:
        online();
        virtual ~online();
        void makeMethod(string Method);
};
    
08.10.2018 / 04:56