Class vs Pointer in LTE (lena) case

26 views
Skip to first unread message

jinyif...@outlook.com

unread,
Mar 14, 2017, 10:27:02 AM3/14/17
to ns-3-users
Dear all

Hi!

I am a newbie in ns3 and C++, I suspect my question is more concerned as a C++ problem, but I just a bit puzzled on the 'smart pointer' or 'Ptr<>'.

Comparing with 802.11p, we initialize a network through :

Wifi80211pHelper wifi80211p = Wifi80211pHelper::Default ();

basically this is the structure of :

Class Type classname = class::method.

but in lte the case becomes different:

Ptr<LteHelper> lteHelper = CreateObject<LteHelper> ();

which basically become:

int *lteHelper;

lteHelper=&LteHelper;

lteHelper.CreateObject<LteHelper> ();

i think there must be a reason for doing so, or else may we go for

LteHelper lteHelper = LteHelper::CreateObject<LteHelper>; ?

I know this can be a quite silly problem, but yet any suggestions or comments is welcomed!

attached with the document page of Ptr<T>: https://www.nsnam.org/docs/doxygen/classns3_1_1_ptr.html#a07865cd0a6aceaa840a30d4961e1bca7

Yifei Jin

Tommaso Pecorella

unread,
Mar 14, 2017, 9:04:17 PM3/14/17
to ns-3-users
Hi,

the question is NOT that silly, and it has to do with inheritance, Attributes and constructors.

Most ns-3 Helper classes are "normal" C++ classes. They are built to make life easier for the users, and they don't have attributes.
If you check their inheritance, they are just plain, normal classes. At most they'll be inheriting from another helper, but NOT from Object or SimpleRefCount.

On the opposite, LteHelper is derived from Object and it does have Attributes.

What's the big difference ?
Easy: a class derived from Object must be created through CreateObject, or its Attributes will not be set. In other words, its member variables will not be set to their default (or non-default) values.

Hope this helps,

T.
Reply all
Reply to author
Forward
0 new messages