Abstract methods do not enforce implementation

6

I'm doing a work and I implemented an abstract method, the case makes a class inherit from it, but the compiler does not accuse error by the lack of implementation of the methods. Am I doing wrong?

class online{
    private:
    public:
        online();
        virtual void build() = 0;
};

class F : public online{
    public:
        F();
};

I would like the F class to be forced to implement the build method.

    
asked by anonymous 04.10.2018 / 15:12

1 answer

-1

You need to make a virtual destructor and put your method as protected. Try enabling the compiler warnings too to see if anything really does.

class Online{    
public:
    virtual ~Online(){}

protected:
    virtual void build() = 0;
};

class Foo : public Online{
    public:
        Foo();
        void build() override;
};
    
19.12.2018 / 06:49