开发者

VC++ inherit from abstract class

开发者 https://www.devze.com 2023-02-16 15:46 出处:网络
I have two classes like this: // parent.h class Parent { public: virtual void Method() = 0; } and //child.h #include \"parent.h\"

I have two classes like this:

// parent.h

class Parent {
    public:
        virtual void Method() = 0;
}

and

//child.h

#include "parent.h"

class Child : public 开发者_运维百科Parent {
    public:
        Child();
        ~Child();
        virtual void Method();
}

//child.cpp

#include "child.h"

Child::Child() { }
Child::~Child() { }

void Child::Method() { }

+

void main() {
    Parent* p = new Child();
}

This works fine with g++ on Linux, but when I try to apply the same pattern in VS 2010 I get:

error C2259: 'Child' : cannot instantiate abstract class

Any ideas why?


I think you need to add public: before your function signature in the header file. g++ might be interpreting it as a private function.

0

精彩评论

暂无评论...
验证码 换一张
取 消