C++代码编译时报错 未知原因,求解
#include"iostream"
using namespace std;
class CBase
{
public :
CBase();
virtual void Walk (){cout<<"CBase:walk"<<endl;}
virtual void Jump(){cout<<"CBase:Jump"<<endl;}
void Run(int speed){cout<<"Cbase:Run:"<<"Speed="<<"Speed="<<speed<<endl;}
};
class CDerivedA:public CBase
{
public:
CDerivedA();
void Walk(){cout<<"CDerivedA:Walk"<<endl;}
void Jump(){cout<<"CDerivedA:Jump"<<endl;}
void Run(int speed){cout<<"CDerivedA:Run"<<"Speed="<<speed<<endl;}
};
int main() {
CBase *pTmp1=new CDerivedA;
pTmp1->Walk();
pTmp1->Run(20);
pTmp1->Run(30);
return 0;
}
报错如下:
"F:\CLion 2018.2.2\bin\cmake\win\bin\cmake.exe" --build C:\Users\Administrator\CLionProjects\test\cmake-build-debug --target test -- -j 2
[ 50%] Linking CXX executable test.exe
f:/load/mingw-17.1/mingw/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\test.dir/objects.a(main.cpp.obj): in function `main':
C:/Users/Administrator/CLionProjects/test/main.cpp:20: undefined reference to `CDerivedA::CDerivedA()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\test.dir\build.make:85: test.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:72: CMakeFiles/test.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:84: CMakeFiles/test.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: test] Error 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CDerivedA的构造函数未实现。