Claus Christmann wrote:
> I apologize for the monologue, but I still have some issues with
> *object instantiation of C++ classes in ns*
> 
> I read up on inherited classes and according to the book the constructor
> of a base class is called when an object of an inherited class is
> instantiated. Example:
> 
> class animal
> {
>  public:
>   aninmal(){cout<<"making an animal"<<endl;};
>   ~animal(){cout<<"unmaking an animal"<<endl;};
> };
> 
> class dog: public animal
> {
>  public:
>   dog(){cout<<"making a dog"<<endl};
>   ~dog(){cout<<"making a dog"<<endl};
> };
> 
> int main()
> {
>  dog * bello = new dog;
>  cout<< " blah ..." <<endl;
>  delete bello; bello = 0;
>  return 0;
> }
> 
> (should) lead to the following output:
> making an animal
> making a dog
>  blah ...
> unmaking a dog
> unmaking an animal
> 
> So the questions remain:
> 
> a) What happens in the mw-node code with the WirelessRoutingModule()
> constructor? Why doesn't it seem to be called?

It is called. Print out some text in the constructor to convince you.

> 
> b) The constructor only calls init(), declared virtual function in
> WirelessRoutingModule. Since BaseWirelessRoutingModule (derived from the
> former) also has a init() function, the WirelessRoutingModule()
> constructor should call the init() of BaseWirelessRoutingModule,
> shouldn't it?
> 
No it should not. This is because by default the parent constructor
(here WirelessRoutingModule()) is called  before the child constructor
when the child constructor is called (here BaseWirelessRoutingModule()).

In your example above, new dog() results in making an animal, making a
dog and not in making a dog, making an animal.

In the parent constructor, the child object is not created yet and if a
function is called  it is a parent's function (print out some text in
WirelessRoutingModule::init() to convince you).

If you want to call BaseWirelessRoutingModule::init() when you create
the object you have to call it in BaseWirelessRoutingModule().

-Laurent

> c) Resulting from that I followed Pedro's guide to get oTcl debugging
> capabilities, but I couldn't get it to run with the mw-node patch. The
> MASH inspector always kills ns with a segmentation fault when tryin gto
> inspect a WirelessRoutingModule oTcl object. Anybody having some input
> on that?
> 
> I apologize for this series of long emails, but somehow it seems that
> there is some basic issues of C++/oTcl/ns2 which I do not understand.
> 
> Thanks in advance for any comment.
> 
> Claus
> 
> 
> Claus Christmann wrote:
>> OK, my mistake...
>>
>> BaseWirelessRouting module is derived from WirelessRoutingModule, but
>> constructors and destructors are not inherited. (Which is a basic C++
>> behavior...)
>>
>> Hence there is no constructor or destructor explicitly given and thus
>> (an empyt) one is created. This auto generated constructor obviously
>> does not call BaseWirelessRoutingModule::init() .
>>
>> Sorry for all the fuzz...
>>
>> Claus
>>
>>
>> Claus Christmann wrote:
>>> Hi list,
>>>
>>> I am working with Laurent's mw-node patch
>>> (http://www.q2s.ntnu.no/~paquerea/ns.html) and am trying to get my own
>>> routing protocol to work.
>>>
>>> Since my routing protocol utilizes several wirelss interfaces it should
>>> be implemented as a WirelessRoutingModule akording to Laurent's
>>> documentation. Unfortunately the constructor for this class seems to be
>>> never called. I assume that is due to the oTcl/C++ duality, which I seem
>>> to be unable to debug.
>>>
>>> The code under consideration is in wireless/wireless-rtmodule.cc, lines
>>> 84pp:
>>>
>>> //! Constructor
>>> /*! Create a new WirelessRoutingModule with an empty routing information
>>>     base.*/
>>> WirelessRoutingModule::WirelessRoutingModule()
>>>   : RoutingModule(),lastUid_(-1),lastRibEntry_(0)
>>> {
>>>     rib_ = new Rib();
>>>     init();
>>> }
>>>
>>> This C++ class is used as a parent later on
>>> (wireless/wirelss-rtmodule.h, lines 173pp):
>>>
>>> class BaseWirelessRoutingModule :  public WirelessRoutingModule {
>>> ...
>>> }
>>>
>>> and BaseWirelssRoutingModule is used in the example provided with the
>>> patch. Unfortunately BaseWirelessRoutingModule does not do anything in
>>> init() (wireless/wireless-rtmodule.cc, lines 488pp)
>>>
>>> void
>>> BaseWirelessRoutingModule::init()
>>> {
>>>     // nothing to do.
>>> }
>>>
>>> Thus it seemes not to matter, that at least using the provided tcl
>>> script it seems never to be called.
>>>
>>> Am I doing somthing wrong in gdb?
>>> *How is it possible that the constructor of a used class is never called?*
>>>
>>> Has anybody any experience in coding a routing protocol for the MW-node
>>> patch or could point me to a source to look at?
>>>
>>> Thanks in advance,
>>>
>>> Claus
>>>
>>>
> 

Reply via email to