【发布时间】:2012-10-19 09:31:44
【问题描述】:
可能重复:
What are the differences between pointer variable and reference variable in C++?
What does a function prototype mean with an ampersand in it?
据我了解,
void bar(int &x) { ... }
似乎意味着通过引用传递x。但是在 C++ 中,已经有指针等。那么有什么区别呢
void bar(int *x) { ... }
// then call by
bar(&x);
除了它更长...我还注意到如果我使用第二种方法,我需要使用->,而不是.,如果我传入struct...为什么?
【问题讨论】:
-
很多骗子。这是一个参考,是的。
-
我似乎你可能需要阅读一些关于 C++ 的内容,谷歌搜索“c++ 参考”将引导你找到很多优秀的文档和概念解释。
标签: c++