I have to different classe:
class text
{ };
class element
{ };
And I want to store them in the class node
:
template <typename T>
class node
{
T cargo;
std::vector<void*> children;
node(T cargo) : cargo(cargo)
{ };
void add_child(T node)
{
this->children.push_back((void*) node);
}
}
So I would call the node this way storing both, text
and element
's:
element div;
text msg;
node<element> wrapper(div);
wrapper.add_child(msg);
EDIT: To get back the content I use T typedef type;
and convert void pointer to (type*)
.
I know that's not very elegant nor functional, but I just can't figure out what's the correct way of doing that. So please tell me if this is practically acceptable and if it is not, how to do that in the proper manner.
Thanks in advance!