Address-of operator

A

Andrey Tarasevich

Stub said:
What does it mean that "C++ silently write and call address-of operators"?

It doesn't seem to mean anything. Why don't you provide the complete
context for this fragment?
 
N

Nilesh

Stub said:
What does it mean that "C++ silently write and call address-of operators"?

It means that you do not have to explicitally write 'operator &', just
as you dont have to write 'operator ='. C++ will silently provide its
own implementation.

Regards,
Nilesh Dhakras
 
R

Ron Natalie

Nilesh said:
It means that you do not have to explicitally write 'operator &', just
as you dont have to write 'operator ='. C++ will silently provide its
own implementation.
Actually that is not true. No implementation is provided by default.
& is just one of those operators that has a native meaning when not
overloaded. This is distinct from the copy assignment operator which
when not declared is implicitly generated.

This is a subtle distinction but examine the following program:

#include <iostream>
using namespace std;

struct B {
B* operator&() {
cout << "B::eek:perator&()\n";
return this;
}
};

struct D : B {
};

int main() {
D d;
&d;
return 0;
}

In this case the &d expression invokes the inheritted B::eek:perator&. If there was an implicitly
generated one (as C++ does for operator=), then the one in B would be hidden and not used.
 
A

Andrey Tarasevich

Nilesh said:
It means that you do not have to explicitally write 'operator &', just
as you dont have to write 'operator ='. C++ will silently provide its
own implementation.

No, there's absolutely nothing in common between copy assignment
operator and operator '&' in this respect. C++ does not "provide its own
implementation" for member operator &, silently or not.
 
W

wogston

No, there's absolutely nothing in common between copy assignment
operator and operator '&' in this respect. C++ does not "provide its own
implementation" for member operator &, silently or not.

I thought it does, unless you define own = operator, copy the members using
their respective = operators. What is the correct wording of this? Seems
that is the only thing you disagree about as far as I can tell.

-w-
 
A

Andrey Tarasevich

wogston said:
I thought it does, unless you define own = operator, copy the members using
their respective = operators. What is the correct wording of this? Seems
that is the only thing you disagree about as far as I can tell.
...

I'm talking about 'operator &'. Once again, C++ does not "provide its
own implementation" for member 'operator &', silently or not.

As for the copy assignment operator, you are right. If you don't declare
one in your class, the compiler will implicitly declare one for you (and
define it, if necessary and possible).
 
N

Nilesh

Ron Natalie said:
Actually that is not true. No implementation is provided by default.
& is just one of those operators that has a native meaning when not
overloaded. This is distinct from the copy assignment operator which
when not declared is implicitly generated.

Thanks Ron for this clarification.

Nilesh Dhakras.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
anuragag27

Latest Threads

Top