The problem with your code is in your head. You are not accepting your compiler’s (superior) understanding of the problem.
There are two kinds of reference: direct and indirect. In C++, we use specific language to distinguish the two:
• an indirect reference is a
pointer
• a direct reference is a
reference
Your argument is a (direct)
reference, not a
pointer.
Hence, you cannot use it like a pointer.
Unless, of course, it is a reference to a pointer, but that is not what you have here.
To add some:
A direct reference (what C++ calls a
reference) is an
alias for some value —two names for the same object.
1 2 3 4 5 6
|
int x = 12;
int& y = x; // both "y" and "x" are names for the same int object
// I can use either name to access the object
y++;
std::cout << x << "\n";
|
An indirect reference (what C++ calls a
pointer) is a value that can be used to
obtain a direct reference to some other value.
1 2 3 4 5 6
|
int x = 12;
int* p = &x; // p is a value that can be used to obtain a reference to x
*p = 7; // First, I convert p into a direct reference to the x object, then modify it
std::cout << x << "\n";
|
I hope helps.