Object creation

21 views
Skip to first unread message

harald...@gmail.com

unread,
Oct 19, 2016, 12:04:38 PM10/19/16
to ns-3-users
I have a Client class, and an abstract Algorithm class, with multiple derived 
Algorithm classes / actual implementations AlgorithmOne and AlgorithmTwo.

I create the client from the main class via a helper class in which I do
Ptr<Application> app = m_factory.Create<TcpStreamClient> ();

and in the TcpStreamClient class I do in the constructor:
Ptr<AlgorithmOne> algoOne = CreateObject<AlgorithmOne>(a, b, c, d);
Note: I want to create the AlgoOne, AlgoTwo, etc... object inside the Client, since the client has to compute a, b, c, d first.



But now I want the client's constructor to be generic, so that I can be able to do something like
template <typename T> TcpStreamClient::TcpStreamClient ()
{
 
Ptr<T> algo = CreateObject<T>(a,b,c,d);
}
and the before mentioned helper class I can do something like
Ptr<Application> app = m_factory.Create<TcpStreamClient<AlgorithmOne>> ();

which is of course obviously doesn't work that way, wrong syntax, etc.
I hope you know what I'm trying to achieve and can help me.
Message has been deleted

harald...@gmail.com

unread,
Oct 19, 2016, 12:48:24 PM10/19/16
to ns-3-users
After having a look at the documentation, I've understood, that when an object is created with 
Create<T>()

(see object-factory.cc) Callback<ObjectBase *> cb = m_tid.GetConstructor (); is called, so it seems to get the constructor from there...
In my
TypeId TcpStreamClient::GetTypeId()
I have
.AddConstructor<TcpStreamClient> ()
which probably must be replaced somehow, because my template constructor doesn't match the default constructor...
How do I do that?
Reply all
Reply to author
Forward
0 new messages