[英]Linker error with g++ and templates
我正在做一个简单的程序,当我找不到编译它的方法时,我正在使用C ++中的模板来实现带有一些数据类型的库。
代码是:
VectorT.cpp文件:
template <class T>
VectorT<T>::VectorT(){
elementos = NULL;
numElementos=0;
}
VectorT.h文件:
#ifndef __VectorT_h__
#define __VectorT_h__
template <class T>
class VectorT{
private:
T * elementos;
int numElementos;
public:
VectorT();
};
#include "VectorT.tpp"
#endif
以及编译方式,并带有错误:
g++ -c -o obj/VectorT.o src/VectorT.cpp -I include/VectorT.h
g++: warning: src/VectorT.cpp: linker input file unused because linking not done
任何想法? 非常感谢。
该“代码”无法编译,因为它仍然不是完整的代码。
这样,您可以编写测试代码,只需要添加头文件。 例如:g ++ -o bin / testVector src / testVector.cpp -I include /该程序无需编译即可运行! 唯一的细节是头文件和cpp文件必须位于/ include文件夹“ VectorT.tpp”和VectorT.h中,以及头文件和模板的实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.