如何在C ++中将指针转换/转换为引用 [英] How to cast/convert pointer to reference in C++

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

问题描述

如何将指针( Object * ob )传递给原型为 void foo(Object&)的函数?

How can I pass a pointer (Object *ob) to a function which prototype is void foo(Object &) ?

推荐答案

这样调用:

foo(*ob);

请注意,根据您的问题标题中的建议,此处没有投射。我们所做的都是去引用对象的指针,然后我们传递给函数。

Note that there is no casting going on here, as suggested in your question title. All we have done is de-referenced the pointer to the object which we then pass to the function.

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

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