undefined reference to `typeinfo for IA' collect2: ld returned 1 exit status
来源:互联网 发布:p2p网络搭建 编辑:程序博客网 时间:2024/06/05 20:39
背景:c++工程,虚函数,继承,接口,代码如下:class IA{public:virtual void printa();};class CA:public IA{public:CA(int a){this->a = a;}~CA(){}public:void printa() {printf ("a=%d\n", a);}private:int a;};int main(int argc, char** argv) {IA* ia = new CA(5);ca->printa();delete ia;return 0;}编译结果如下:undefined reference to `vtable for IA'undefined reference to `typeinfo for IA'collect2: ld returned 1 exit status分析:1、在IA类中未定义涉及到虚表2、在CA类中未定义涉及IA类信息3、连接错误根据以上3点和代码,可以知道:1、如果IA是接口类型那么virtual void printa() = 0;2、如果IA是基类那么至少是virtual void printa(){} 而不能没有实现。解决:1、当做接口使用,IA类修改如下:virtual void printa() = 0;2、当做基类使用,IA类修改如下:virtual void printa(){}
0 0
- undefined reference to `typeinfo for IA' collect2: ld returned 1 exit status
- undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status
- undefined reference to `libiconv_open' collect2: ld returned 1 exit status
- undefined reference to `pthread_create' collect2: ld returned 1 exit status
- pthread线程创建出现undefined reference to `pthread_create' collect2: error: ld returned 1 exit status
- GCC 中 undefined reference to ‘ceil’ collect2:ld returned 1 exit status 错误
- 【错误笔记】undefined reference to `sqrt' collect2: ld returned 1 exit status
- Linux gcc编译提示:undefined reference to `sqrtf' collect2: error: ld returned 1 exit status
- GCC 中 undefined reference to ‘ceil’ collect2:ld returned 1 exit status 错误
- undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit stat
- 编译器错误:/tmp/ccyOgqYQ.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status
- cocos2dx向android平台移植出现问题undefined reference to 'sqlite3_close' collect2: ld returned 1 exit status
- collect2: ld returned 1 exit status
- collect2 : ld returned 1 exit status
- 提示collect2: ld returned 1 exit status
- QtCreator : collect2 ld returned 1 exit status
- error: collect2: ld returned 1 exit status
- error: collect2: ld returned 1 exit status
- 关于网狐棋牌6603源码的整理、编译和搭建
- OPC接口使用技巧
- C++中delete和delete[]的区别
- spring 输出json问题
- C# 读取文件
- undefined reference to `typeinfo for IA' collect2: ld returned 1 exit status
- 数据结构之栈的Java实现
- Build和Rebuild的区别
- Best Time to Buy and Sell Stock
- C#读取.sql文件并执行文件中的sql
- Module.h 网狐的“com”工具箱
- 9.4 滚动条类
- 获取批处理文件所在路径
- 百度的echart环形图颜色动态设置