关于GCC模板出现"undefined reference to"的错误
来源:互联网 发布:淘宝店铺引流工具 编辑:程序博客网 时间:2024/05/21 13:14
关于GCC模板出现"undefined reference to"的错误
分类: C++2010-06-09 23:38 920人阅读 评论(0) 收藏 举报
referencegccclass编译器
今天晚上编译模板,将声明和实现分离开了,结果总是报“undefined reference to”的错误,调试了好久,也没发现代码中有什么错误的地方,就写了个简单的模板类,还是发现报同样的错误,郁闷了下,最后发现把声明和实现写在一起就不会出现错误了,又到晚上搜了下,结果还是真的是关于声明和实现分开的关系。
原因是由于GCC不支持模板类的分离编译,只能声明和实现写在一起编译了。
- #ifndef A_H_INCLUDED
- #define A_H_INCLUDED
- template <class Type>
- class A{
- Type i;
- public:
- A():i(0) { }
- A(const Type& _i):i(_i) { }
- Type& pop();
- ~A(){ }
- };
- #endif // QUEUE_H_INCLUDED
- #include "A.h"
- template <class Type>
- Type& A<Type>::pop()
- {
- return i;
- }
这样就会报错,是由于GCC编译器不支持模板类的分离编译
- #ifndef A_H_INCLUDED
- #define A_H_INCLUDED
- template <class Type>
- Type& A<Type>::pop()
- {
- return i;
- }
- template <class Type>
- class A{
- Type i;
- public:
- A():i(0) { }
- A(const Type& _i):i(_i) { }
- Type& pop();
- ~A(){ }
- };
- #endif // A_H_INCLUDED
这样就不会报错了,以后在GCC写模板类的时候要记得将声明和实现放在一起哦!!!
- 关于GCC模板出现"undefined reference to"的错误
- 关于GCC模板出现"undefined reference to"的错误
- gcc 编译出现undefined reference to‘pthread_create’的错误
- 关于 undefined reference to 的错误
- GCC编译uboot出现(.ARM.exidx+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'错误的解决办法
- gcc编译出现 undefined reference to 的问题
- gcc编译出现undefined reference to 'pthread_create'的解决方法
- gcc编译出现undefined reference to 的问题
- gcc编译出现”undefined reference to `pcap_parse’”
- gcc 编译错误:"undefined reference to 'sqrt'
- 调用模板类出现 undefined reference 错误的解决方法
- 调用模板类出现 undefined reference 错误的解决方法
- 交叉编译中出现的 'Undefined reference to __aeabi_read_tp' 错误
- 编译什么时候出现Undefined reference to 的错误
- linux编译出现undefined reference to `pow‘的错误
- gcc/g++ 出现.../crt1.o: In function `_start': (.text+0x18): undefined reference to `main'的错误
- gcc undefined reference to
- 为什么会出现undefined reference to ''错误
- merge attachDirty attachClean用法.
- valgrind使用心得
- Google China New Grad Test 2014 Round A Problem D
- 简单链式结构删除
- ASP.NET伪静态的实现及伪静态的意义
- 关于GCC模板出现"undefined reference to"的错误
- 《UNIX环境高级编程》笔记--umask函数
- Cocos2d-x 详解坐标系统
- 利用Excel VBA将坐标点直接转换为谷歌地球的kml格式文件(ExcelToKml)
- 11个强大的Visual Studio调试小技巧
- 记一个C++ 开发SSH的英文网站
- jQuery函数学习
- DataGridview 动态绑定Combox
- 开放windows服务器端口-----以打开端口8080为例