Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

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.2incmakewinincmake.exe" --build C:UsersAdministratorCLionProjectsestcmake-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: CMakeFilesest.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]: *** [CMakeFilesest.diruild.make:85: test.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFilesMakefile2:72: CMakeFiles/test.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFilesMakefile2:84: CMakeFiles/test.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: test] Error 2

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

CDerivedA的构造函数未实现。

C:/Users/Administrator/CLionProjects/test/main.cpp:20: undefined reference to `CDerivedA::CDerivedA()'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...