J
JKop
You know the whole "Linked List" concept, where each object knows where the
the next one is. Well, in one of its simplest forms I have:
template<class T>
struct LinkedObject : virtual public T
{
LinkedObject* p_next;
};
The only problem here is in calling the constructor:
#include <string>
int main()
{
LinkedObject<std::string> blah("Monkey!");
blah.p_next = new LinkedObject<std::string>("Ape!");
delete blah.p_next;
}
Is there any way to achieve something akin to the above, whereby the call to
the derived class's constructor "filters through" to the base class's
constructor... ?
What I'm trying to achieve is that an object of type "LinkedObject
<std::string>" will behave exactly as would an object of type
"std::string" - the only difference being that you can do:
blah.p_next = 0;
As such, I want the call to the constructor of "LinkedObject<T>" to fall
through to the constructor of the base class.
-JKop
the next one is. Well, in one of its simplest forms I have:
template<class T>
struct LinkedObject : virtual public T
{
LinkedObject* p_next;
};
The only problem here is in calling the constructor:
#include <string>
int main()
{
LinkedObject<std::string> blah("Monkey!");
blah.p_next = new LinkedObject<std::string>("Ape!");
delete blah.p_next;
}
Is there any way to achieve something akin to the above, whereby the call to
the derived class's constructor "filters through" to the base class's
constructor... ?
What I'm trying to achieve is that an object of type "LinkedObject
<std::string>" will behave exactly as would an object of type
"std::string" - the only difference being that you can do:
blah.p_next = 0;
As such, I want the call to the constructor of "LinkedObject<T>" to fall
through to the constructor of the base class.
-JKop