父類否 '空隙TestSub ::打印()' 的成員函數類 'TestSub'
class Test {
public:
Test(){};
virtual ~Test(){};
void print() { cout<<1<<endl;};
};
子類中聲明的.h定義
class TestSub: public Test {
public:
TestSub();
virtual ~TestSub();
};
子類的.cpp實現
#include "TestSub.h"
TestSub::TestSub() {
}
TestSub::~TestSub() {
}
void TestSub::print(){
cout<<2<<endl;
}
int main(){
TestSub *t=new TestSub();
t->print();
}
原因:
.. \ src \ TestSub.cpp:17:2 1:錯誤:no'TestSub :: print()'成員函數在類'TestSub'中聲明
你忘了這個類型..而不是'void TestSub :: print()'。 – Rapptz
我照你所說的做,但不彈出'void TestSub :: print()' – jiafu