如何将指向引用的指针作为参数传递给函数-Objective C [英] How to pass pointer to a reference as an argument to a function-Objective C

查看:86
本文介绍了如何将指向引用的指针作为参数传递给函数-Objective C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C++ 中,我们将把指向函数的指针作为

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

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

如何在 Objective C 中声明它?

How to declare this in Objective C?

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

但我需要使用指向引用的指针 (RsEvent*&).我在这里只使用了指针 (RsEvent*) 作为数据类型.

But i need to use the pointer to reference (RsEvent*&). I have used only pointer (RsEvent*) as a datatype here.

推荐答案

你需要使用指针来模拟 C(和 Objective-C)中的引用:

You need to use pointers to simulate reference in C (and Objective-C):

-(BOOL)getData:(REMOTE_ID)msId withEvent:(RsEvent**)pEvent {
   // do stuff with msId and *pEvent
}

并将参数作为指针传入:

and pass in the argument as a pointer:

RsEvent* event;
BOOl res = [foo getData:msId withEvent:&event];
...

这篇关于如何将指向引用的指针作为参数传递给函数-Objective C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆