convert reference to pointer representation in C++(将引用转换为 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++ 中的指针表示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将引用转换为 C++ 中的指针表示


- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- Stroustrup 的 Simple_window.h 2022-01-01
- C++ 协变模板 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 近似搜索的工作原理 2021-01-01
- 静态初始化顺序失败 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 从python回调到c++的选项 2022-11-16