c++ - instantiated from here error -
My compiler is torturing me with this instant error which I can not fully understand.
I have the template class list item:
template & lt; Class T & gt; Class tListItem {public: tListItem (tt) {tData = t; Next = 0;} tListItem * Next; T data () {return tData;} private: t tudata; };
If I try to start an object with a non-primitive data type like-:
sPacket zomg ("whaever", 1) I am TListItem & LT; SPacket & gt; Z (ZOMG);
My compiler always throws this error. The error isn along with the primitive types are thrown away.
The output from the compiler is:
./linkedList/tListItem.h: constructor at TLITIT & lt; T & gt; :: tListItem (t) [t = with sPacket] ': recvBufTest.cpp: 15: from here immediately ../linkedList/tListItem.h:4: error: to call' packet :: call packet () ' No matches for '../packetz/sPacket.h:2: Note: Candidates are: sPacket :: sPacket (const char *, int) ../packetz/sPacket.h: 1: Note: sPacket :: sPacket (const sPacket & amp; ;)
I will not bother you, but I do not want to spend 2 hours with something stupid ..... thx for all your replies
As it stands, your code needs a default constructor for type T. Your Template Constructor:
tListItem (tt): tData (t), next (0) {}
The difference is that your version is the default one Example makes type T and then specify it. My version uses an initial list to copy the creation of the example, so no default constructor is necessary.
Comments
Post a Comment