开发者

initialisation list in c++

开发者 https://www.devze.com 2023-03-10 09:59 出处:网络
I barely know c++.Not an expert. I am looking through an already existing code. I could not able to understand this following code.

I barely know c++.Not an expert.

I am looking through an already existing code. I could not able to understand this following code.

typedef enum
{
    eEvent_MsgOk,            
    eEvent_InvalidMsgId,    
    eEvent_Failure,          
} eEventTy开发者_如何学编程pe;

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 initialisation list they are intialising the values.

But the Rs232Msg class doesnt have a single parameterised constructor.

But its having a constructor which accepts 4 parameters.

I could not identify how its getting invoked.But the code runs without any error.


m_pMsg isn't an Rs232Msg class. Rather, its a pointer to an Rs232Msg class. All that is being copied is a pointer to an already-existing instance of that class, so the constructor isn't being invoked here.


m_pMsg and pMsg are pointers to Rs232Msg, so the Rs232Msg constructor isn't being invoked; you're just storing a pointer to a preexisting instance.

0

精彩评论

暂无评论...
验证码 换一张
取 消