Create New Classes in Scratch Folder to be used by Different Main Programs in NS3

548 views
Skip to first unread message

sander...@gmail.com

unread,
Apr 20, 2016, 4:37:22 AM4/20/16
to ns-3-users
Hello,

As part of my ns3 project, I have to create new class in ns3 lets say my_project.cc and my_project.h, both files are places in a scratch/my_project subfolder. Now I want these classes to be used by different other main programs other than the one defined in scratch/my_project/ folder (i.e. main.cc). But whenever I try to use that class from the main program (main2.cc) in my scratch folder (scratch/) by include the corresponding .h file (my_project.h) it gives me error like undefined reference to MyProject::MyProject(), etc...

Is there anyone who can help me, in using the class defined in scratch subfolder at different places (main programs) without creating a new module in ns3?

Thanks

Tommaso Pecorella

unread,
Apr 20, 2016, 5:29:36 AM4/20/16
to ns-3-users
Hi,

you have to put all the classes / headers in a folder in the scratch directory. See for example the scratch/subdir

T.

sander...@gmail.com

unread,
Apr 20, 2016, 5:51:08 AM4/20/16
to ns-3-users
Hi,

You mean that all of my main programs that are using my new class (my_project.cc & my_project.h) have to be placed within the same subfolder of scratch i.e. scratch/my_project/ . Is there no possibility (other than creating a new module) that by adding (#include<ns3/my_project.h>) I can use my_project class where ever I want?

Tommaso Pecorella

unread,
Apr 20, 2016, 6:27:09 AM4/20/16
to ns-3-users
Each subfolder is compiled as a single script. As a consequence, it must have only ONE "main".
About the second question, the answer is yes, Other than creating a new module, that's what you have to do.

T.

Thomas Sanders

unread,
Apr 20, 2016, 6:51:01 AM4/20/16
to ns-3-users
Thanks Tommaso for your reply!

I have one last imp question,  I am passing some argument to the constructor of 'MyClass' i.e. MyClass::MyClass(Ptr<int> j, uint_16 x, ...) , so I want to know how should I define these argument in the .AddConstructor? because in the current version (below) it gives error. I tried changing the definition but the error didn't resolve.

             NS_OBJECT_ENSURE_REGISTERED (MyClass)
             TypeId MyClass::GetTypeId (void)
                 {
                          static TypeId tid = TypeId("ns3::MyClass") .
                          SetParent<MobilityModel> () .
                          SetGroupName ("Mobility") .
                          AddConstructor <MyClass> ();
                 }

Best,

Thomas Sanders

unread,
Apr 20, 2016, 6:58:05 AM4/20/16
to ns-3-users
Just wanna add that, I tried changing the definition of .AddConstructor in GetTypeId(void) by including the passed arguments to the constructor but the error in .../ns3/type-id.h saying no matching function for call to 'ns3::MyClass::MyClass()' persists. 

meiming yu

unread,
Oct 19, 2017, 9:25:54 PM10/19/17
to ns-3-users
Hi

Have you solve your problem, I met the same problem with you, when I execute the program, I met the problem of no matching function for call to ‘ns3::VBFUanHeader:VBFUanHeader(). 

If you have solved the problem, please help me.

Thanks for your time.

在 2016年4月20日星期三 UTC+8下午6:58:05,Thomas Sanders写道:
Reply all
Reply to author
Forward
0 new messages