Initialization List in C ++

I almost don't know C ++. Not an expert.

I am looking at existing code. I could not understand this following code.

typedef enum
{
    eEvent_MsgOk,            
    eEvent_InvalidMsgId,    
    eEvent_Failure,          
} eEventType;

class Rs232Event
{
public:
    Rs232Msg*     m_pMsg;    
    eEventType     m_eEvent;   

}
Rs232Event::Rs232Event(eEventType eEvent,Rs232Msg* pMsg)
 :  m_pMsg(pMsg), m_eEvent(eEvent)
{
    // not implemented on purpose
}

Here, using the initialization list, they initialize the values.

But the Rs232Msg class does not have one parameterized constructor.

But he has a constructor that takes 4 parameters.

I could not determine how his call was causing. But the code works without errors.

+3
source share
2 answers

m_pMsgnot a class Rs232Msg. Rather, it is a pointer to a class Rs232Msg. Everything that is copied is a pointer to an existing instance of this class, so the constructor is not called here.

+6
source

m_pMsg pMsg Rs232Msg, Rs232Msg ; .

+1

All Articles