c++ question

Hi,

This question is related with c++ and WebSocketTest.cpp file from cocos2d-x.

In WebSocketTest.cpp (https://github.com/cocos2d/cocos2d-x/blob/cocos2d-x-2.1.5/samples/Cpp/TestCpp/Classes/ExtensionsTest/NetworkTest/WebSocketTest.cpp) we see this:

WebSocketTestLayer::WebSocketTestLayer()
: *wsiSendText
,*wsiSendBinary(NULL)
, *wsiError
,*sendTextStatus(NULL)
, *sendBinaryStatus
,*errorStatus(NULL)
, *sendTextTimes
,*sendBinaryTimes(0)
{


}

What is the meaning of these:
*wsiSendText
,*wsiSendBinary(NULL)

Are initializations of private vars? Where can I learn more about these?

Thanks!

This is called “initialization list”. Here is some information http://www.cprogramming.com/tutorial/initialization-lists-c++.html

Thank you very much!

Critical in Cocos2d-x for using CC_SYNTHESIZE_RETAIN

Can you put an example about the importance of CC_SYNTHESIZE_RETAIN and the initialization lists?

Thank you

As far as I know, you must use an initialization list for all CC_SYNTHESIZE_RETAIN properties.

This is because CC_SYNTHESIZE_RETAIN will automatically attempt to release the old value when you set the new value.

If you set a new value without the initialization list, when CC_SYNTHESIZE_RETAIN goes to release the old value, it will be NULL and you will crash.

Therefore, to use CC_SYNTHESIZE_RETAIN you must make use of an initialization list to construct the private variables.

[*] Everything I learned here I got from reading the CC2D-x source code. There are probably other ways to do it.

Thank you