user2693439
user2693439

Reputation: 31

C++: what does this constructor format mean?

I,m reading a c++ code , and i can't understand a section of it . here is the code :

    BatteryBase.h

 00001 
00002 #ifndef __Battery_Base_H__
00003 #define __Battery_Base_H__
00004 
00005 #include "CommonIncludes.h"
00006 #include "cConsumer.h"
00007 #define SUCCESS 1
00008 #define FAIL 0
00009 #define BATTERY_OUT 2
00010 
00012 
00017 class BatteryBase : public cSimpleModule
00018 {
00019         protected:
00020                 double      m_Energy;
00021                 double      m_CurrentEnergy;
00022                 int         m_State;
00023                 cModule     *pCoOrdinator; 
00024                 cArray      ConsumerList;
00025                 simtime_t lastTimeOut; 
00026                 cMessage *batteryOut;
00027                 cConsumer *consumer;
00028 
00029         public:
00030                 Module_Class_Members(BatteryBase, cSimpleModule, 0); //constructo
00031                 
00032 
00034 
00036                 virtual double GetTotalEnergy(void) const;
.
.
.
00088                 virtual void handleMessage(cMessage *msg) = 0;
00089 
00091 
00094                 virtual int RegisterCoordinator(void);
00095 };
00096 
00097 #endif // __Battery_Base_H__

I can't understand what does it mean in line 32. why the BatteryBase class constructor uses the BatteryBase class as parameter ? whould you help me please?

Upvotes: 3

Views: 211

Answers (2)

Pierre Fourgeaud
Pierre Fourgeaud

Reputation: 14510

Module_Class_Members(BatteryBase, cSimpleModule, 0); //constructor

This is not the constructor of your class. The constructor of your class would be something like :

BatteryBase() {}

Module_Class_Members is a MACRO that was helping the developer to create a default constructor for his class. In your case, it creates a constructor who should look like :

BaseClass() : cSimpleModule() {}

But as it is said in the documentation that this macro is deprecated, you should replace it by :

public:
    BaseClass() : cSimpleModule() {}

Upvotes: 3

user2339071
user2339071

Reputation: 4310

It is a macro that calls constructor and sets up inheritance relationships. Module_Class_Members(BatteryBase, cSimpleModule, 0). It means that the class BatteryBase has been derived from cSimpleModule that is an abstract class which provides basic functionality for any module. Will give you another example. For e.g.

class MyDerivedModule : public MyModule
{

Module_Class_Members (MyDerivedModule,MyModule, 0);    
// and again user-specific methods
// follow
};` 

Hope it answers your question.

Upvotes: 0

Related Questions