How to pass pointer to a reference as an argument to a function-Objective C

前端 未结 2 1965
北海茫月
北海茫月 2021-01-24 13:17

In C++ we will pass the pointer to a function as

bool getData(REMOTE_ID msId,RsEvent*& pEvent);

How to declare this in Objective C?

<
2条回答
  •  一向
    一向 (楼主)
    2021-01-24 13:37

    (By the way, you're not dealing with a pointer to a reference, but a reference to a pointer.) Can't you just use the same type annotation in the Objective-C method?

    - (BOOL)getData:(REMOTE_ID)msId withEvent:(RsEvent*&)pEvent;
    

    I think that should work, but if it doesn't, you can use a pointer to a pointer instead:

    - (BOOL)getData:(REMOTE_ID)msId withEvent:(RsEvent**)pEvent {
      useEvent(*pEvent); // when using the event, you need to dereference the pointer
    }
    

    Send the -getData:withEvent: message with the address of your event:

    [obj getData:SOME_ID withEvent:&event];
    

提交回复
热议问题