How to assign the values for the parameters
How to assign the values for the parameters.
Rs232MsgRawEncoded(const int nMsgId,const INT8U* pSrc=NULL,unsigned int nSize=0);
I have declared the above cpp method declaration in Objective C as the following
-(id)initWithRS232MsgRawEncoded:(const int)nMsgId withpSrc:(c开发者_运维技巧onst uint8_t*)pSrc withSize:(unsigned int)nSize;
Inside the function i'm checking whether its null or with some value.
I could not able to declare the variables as pSrc=NULL and nSize=0 in the Objective C Is there any way to do this?
Objective-c (as well as c) does not support default parameters for functions.
So you can either use the function you have and pass all parameters to it every time. If you don't - create new functions with some parameters omitted and call your 'main' function with default parameters inside, e.g.:
-(id)initWithRS232MsgRawEncoded:(const int)nMsgId{
return [self initWithRS232MsgRawEncoded:nMsgId withpSrc:NULL withSize:0];
}
精彩评论