开发者

Objective-C reference to a pointer declaration getting error

I had this declaration.

- (BOOL)getNHPData:(REMOTE_M开发者_如何转开发ESS_ID)msgId withEvent:(RSEvent*&)pEvent;

I tried with RSEvent** also but i'm getting this error for 2 times

Expected ')' before RSEvent

Why is it so.


Objective-C is a superset of the C language and does not have references. If you want to use C++-style references in Objective-C, you must compile as Objective-C++ (as you might expect, Objective-C++ is a superset of C++). Use the .mm extension to automatically use the Objective-C++ in Xcode.

If the method in question is a public API that will be consumed from Objective-C, I would highly recommend using a pointer-to-pointer (RSEvent**) instead of a pointer reference. Using Objective-C++ in a header "infects" clients with Objective-C++ (unless you're very careful). Objective-C++ takes much longer to compile that Objective-C and you will eventually run into the inevitable C vs. C++ incompatibilities. Standard practice is to hide Objective-C++ from public APIs whenever possible.


I personally have never had much success in c++ or obj-c with pointer references, if I need that kind of functionality, I usually just use a pointer pointer like this:

some function()
{
    RSEvent *pEvent = new RSEvent();
    [self getNHPData:DEFAULT_MSG_ID withEbvent:&pEvent];
}

- (BOOL)getNHPData:(REMOTE_MESS_ID)msgId withEvent:(RSEvent**)pEvent
{
    //Do some stuff
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜