将引用转换为 C++ 中的指针表示 [英] convert reference to pointer representation in C++

查看:25
本文介绍了将引用转换为 C++ 中的指针表示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 C++ 中转换"对指针的引用?在下面的例子中,func2 已经定义了原型,我不能改变它,但是 func 是我的 API,我想要么传递两个参数,要么传递一个(第二个设置为 NULL)或两者都不设置(都设置为 NULL):

Is there a way to "convert" a reference to pointer in c++? In example below, func2 has already defined prototype and I can't change it, but func is my API, and I'd like to either pass both parameters, or one (and second set to NULL) or neither (both set to NULL):

void func2(some1 *p1, some2 *p2);

func(some1& obj, some2& obj2)
{
   func2(..);
}

推荐答案

func2(&obj, &obj2);

像普通变量一样使用引用参数.

Use reference parameters like normal variables.

这篇关于将引用转换为 C++ 中的指针表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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