我的编译器用这个我完全不理解的实例化错误来折磨我。
我有模板类listItem:
template <class T>
class tListItem{
public:
tListItem(T t){tData=t; next=0;}
tListItem *next;
T data(){return tData;}
private:
T tData;
};
如果我尝试使用非原始数据类型初始化它的对象,例如:
sPacket zomg("whaever",1);
tListItem<sPacket> z(zomg);
我的编译器总是抛出这个错误。这个错误是用原始类型抛出的。
编译器的输出是:
../linkedList/tListItem.h: In constructor ‘tListItem<T>::tListItem(T) [with T = sPacket]’:
recvBufTest.cpp:15: instantiated from here
../linkedList/tListItem.h:4: error: no matching function for call to ‘sPacket::sPacket()’
../packetz/sPacket.h:2: note: candidates are: sPacket::sPacket(const char*, int)
../packetz/sPacket.h:1: note: sPacket::sPacket(const sPacket&)
我不会打扰你,但我不想花 2 个小时做一些愚蠢的事情......所以谢谢你所有的回复