don*_*lmg 0 c++ undefined-reference
我有一堂课,比如:
基础.h
class Base {
public:
Base();
virtual int getInfo(int i);
protected:
int GetDetail (int iVal);
}
inline int Base::getInfo(int i){
int output = GetDetail(i);
return output;
};
Run Code Online (Sandbox Code Playgroud)
Ib Base.cpp,我定义了GetDetail。
int Base::GetDetail(int i){
int output;
// do work to output
return output;
}
Run Code Online (Sandbox Code Playgroud)
我有一些派生类从它们自己的实现 getInfo() 中调用 GetDetail。
当我从 Base.h 中的虚拟函数定义中删除对 getInfo() 的调用时,代码将使用派生类自己的实现进行编译。
当我使用从内联虚拟函数调用 GetDetail 的虚拟函数进行编译时,链接失败并显示:
对 GetDetail 的未定义引用。
有任何想法吗?
class Base {...};作为参考,我可以使用 g++ 4.4.3 成功编译/链接您的示例(已添加分号)。
| 归档时间: |
|
| 查看次数: |
3496 次 |
| 最近记录: |