c++ - using templates in a struct -
i need have variable struct inside struct. so, want able include data kind of struct in struct. think possible template isn't working out:
namespace basestructs { template<typedef t> struct packet { int id; t data; }; }
so, have if make object of struct this:
basestructs::packet packet;
it doesn't work because program wants me choose template struct want "data" variable changeable. ideas on how solve this?
what want create small object holds id in example , need add data object (which might differ in number of variables , such).
a template struct - template. impossible initialize instance of template without giving specific type should locked to. when happens, new concrete type created templte.
for example, code:
basestructs::packet<foo> foopacket; basestructs::packet<bar> barpacket;
would cause compiler create 2 new concrete types following definitions:
struct { int id; foo data; }; struct { int id; bar data; };
the original template struct still exists. neither of these new types cause change meaning.
Comments
Post a Comment