VC++ inherit from abstract class
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.
精彩评论