【发布时间】:2012-11-14 17:16:36
【问题描述】:
//Parent.h
class Parent{
public:
Parent(){}
~Parent(){}
virtual void func1() = 0;
};
//Child.h
#include "Parent.h"
class Child : public Parent{
int x, y;
public:
Child() : Parent(){ //constructor
}
virtual void func1();
};
//Child.cpp
#include "Child.h"
void Child::Parent::func1(){
}
这编译得很好,但是,我想把 Child 类的构造函数(和析构函数)的实现放在它的 cpp 文件中,可以吗?怎么样?
我已经尝试了下面的代码,但它引发了对 vtable for Child 的未定义引用
Child::Child() : Parent(){ //in the cpp
}
Child(); //in the header file
Child():Parent(); //also tried this one
【问题讨论】:
标签: c++ inheritance constructor destructor