I know Class *cls is a pointer, and Class &cls takes the address, but what is
void fucction1( Class *&cls)
If I have Class c
, what should I pass to function1()
?
Thanks!
Besides, what James explained in his response, let me add one more important point to it.
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 from the language specification reads,
There shall be no references to references, no arrays of references, and no pointers to references.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With