By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,406 Members | 888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,406 IT Pros & Developers. It's quick & easy.

Address-of operator

P: n/a
What does it mean that "C++ silently write and call address-of operators"?
Jul 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Stub wrote:
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?

--
Best regards,
Andrey Tarasevich

Jul 19 '05 #2

P: n/a
"Stub" <st**@asof.com> wrote in message news:<yX*********************@bgtnsc05-news.ops.worldnet.att.net>...
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
Jul 19 '05 #3

P: n/a

"Nilesh" <dh*******@hotmail.com> wrote in message news:ae**************************@posting.google.c om...
"Stub" <st**@asof.com> wrote in message news:<yX*********************@bgtnsc05-news.ops.worldnet.att.net>...
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.

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::operator&()\n";
return this;
}
};

struct D : B {
};

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

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


Jul 19 '05 #4

P: n/a

Nilesh wrote:
"Stub" <st**@asof.com> wrote in message news:<yX*********************@bgtnsc05-news.ops.worldnet.att.net>...
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.


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.

--
Best regards,
Andrey Tarasevich

Jul 19 '05 #5

P: n/a
> 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-
Jul 19 '05 #6

P: n/a
wogston wrote:
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.
...


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).

--
Best regards,
Andrey Tarasevich

Jul 19 '05 #7

P: n/a
"Ron Natalie" <ro*@sensor.com> wrote in message news:<3f***********************@news.newshosting.c om>...
"Nilesh" <dh*******@hotmail.com> wrote in message news:ae**************************@posting.google.c om...
"Stub" <st**@asof.com> wrote in message news:<yX*********************@bgtnsc05-news.ops.worldnet.att.net>...
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.

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.
Jul 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.