Method for solving error: “cannot instantiate abstract class”

前端 未结 3 1789
情话喂你
情话喂你 2020-12-17 16:45

I find one of the most time-consuming compiler errors for me is \"cannot instantiate abstract class,\" since the problem is always that I didn\'t intend for the class to be

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-17 17:26

    C++Builder tells you which method is abstract:

    class foo {
        virtual void x() const = 0;
    };
    
    class bar : public foo {
        virtual void x() { }
    };
    
    new bar;
    

    [BCC32 Error] File55.cpp(20): E2352 Cannot create instance of abstract class 'bar'
    [BCC32 Error] File55.cpp(20): E2353 Class 'bar' is abstract because of 'foo::x() const = 0'
    

提交回复
热议问题