什么是“Class *& cls”是什么意思在C ++的函数定义? [英] What does "Class* &cls" mean in C++'s function definition?
问题描述
我知道Class * cls是一个指针,Class& cls获取地址,但是是什么
I know Class *cls is a pointer, and Class &cls takes the address, but what is
void fucction1( Class *&cls)
如果我有 Class c
,我应该传递给 function1()
?
If I have Class c
, what should I pass to function1()
?
谢谢! $ b
推荐答案
Besides, what James explained in his response, let me add one more important point to it.
您可以写 Class *&
(指针在C ++中完全有效,你不能写 Class& *
(指向引用的指针),因为不能具有指向任何类型的引用的指针。在C ++中,指向引用的指针是非法的。
While you can write Class* &
(reference to pointer) which is perfectly valid in C++ only, you cannot write Class& *
(pointer to reference), as you cannot have a pointer to a reference to any type. In C++, pointer to reference is illegal.
§8.3.2/ 4从语言规范中读取,
§8.3.2/4 from the language specification reads,
不能引用
引用,没有引用数组,
和没有指向引用的指针。
如果我有类c,我应该将
传递给function1 )?
If I have Class c, what should I pass to function1()?
您可以这样编写您的调用代码:
You can write your calling code like this:
Class *ptrClass;
//your code; may be you want to initialize ptrClass;
function1(ptrClass);
//if you change the value of the pointer (i.e ptrClass) in function1(),
//that value will be reflected here!
//your code
这篇关于什么是“Class *& cls”是什么意思在C ++的函数定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!