Error: expected class-name before

Asked

Viewed 129 times

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 on an online class object. When I do this error happens due to 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 to resolve this error?

1 answer

0


Declare the class before setting it, it can 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 you already have, which can be after it has 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);
};

I put in the Github for future reference.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.