有没有办法在 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++ 中的指针表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!