Class VC++从抽象类继承

Class VC++从抽象类继承,class,visual-c++,abstract,Class,Visual C++,Abstract,我有两门课是这样的: // parent.h class Parent { public: virtual void Method() = 0; } 及 + 这在Linux上的g++上运行良好,但当我尝试在VS 2010中应用相同的模式时,我得到: error C2259: 'Child' : cannot instantiate abstract class 你知道为什么吗 我认为您需要在头文件中的函数签名之前添加public:。g++可能将其解释为私有函数。它是

我有两门课是这样的:

// parent.h

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

+

这在Linux上的g++上运行良好,但当我尝试在VS 2010中应用相同的模式时,我得到:

error C2259: 'Child' : cannot instantiate abstract class

你知道为什么吗

我认为您需要在头文件中的函数签名之前添加public:。g++可能将其解释为私有函数。

它是公共的,我写错了,头文件中也有构造函数和析构函数定义。您是否使用g++和VS2010编译完全相同的文件?确定不是打字错误吗?g++的行为是正确的。我将这些文件重新组装到一个新项目中,这次一切正常。。所以我猜某处有个打字错误。你是对的
//child.cpp

#include "child.h"

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

void Child::Method() { }
void main() {
    Parent* p = new Child();
}
error C2259: 'Child' : cannot instantiate abstract class