 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
lovecreatesbeauty Guest
|
Posted: Fri Apr 29, 2005 3:46 am Post subject: Predefined class member functions and inheritance |
|
|
Predefined class member functions and inheritance
How many member functions on earth can be provided (predefined) by
standard-compliant compilers?
Scott Meyers says that there are 6: (1)default constructor, (2)copy
constructor, (3)destructor, (4)assignment operator, (5)address-of
operator (non-const), (6)address-of operator (const), in `Effective
C++, 2nd` item 45.
Bjarne Stroustrup mentioned one more: operator, (i.e. comma operator)
in `The C++ programming Language, special edition` section 11.2.2.
Derived classes won't inherit these member functions provided
(predefine) by compilers from father classes, right?
Thank you
lovecreatesbeauty
|
|
| Back to top |
|
 |
Ron Natalie Guest
|
Posted: Fri Apr 29, 2005 12:44 pm Post subject: Re: Predefined class member functions and inheritance |
|
|
lovecreatesbeauty wrote:
| Quote: | Scott Meyers says that there are 6: (1)default constructor, (2)copy
constructor, (3)destructor, (4)assignment operator, (5)address-of
operator (non-const), (6)address-of operator (const), in `Effective
C++, 2nd` item 45.
|
If Scott actually says what you say, he's wrong. The only FUNCTIONS
provided are the default constructor, the copy constructor, the
destructor, and the copy-assignment operator.
It is possible to override other operators for the class (such as
ampersand and comma) but these aren't "predefined member functions"
but intrinsic operators that can be replaced.
| Quote: | Derived classes won't inherit these member functions provided
(predefine) by compilers from father classes, right?
|
Constructors and destructors aren't "inheritted". The copy-assignment
operator (as you noted) is covered up with either the compiler generated
one or a user defined one in the derived class.
As for the operators& and ,. There is no intrisicly operator function
generated when these are not-defined. If you don't define one, then the
default behavior occurs. If you define one in a base class and don't
overload it, the derived class if it can be converted to the base, will
be:
struct A {
A* operator&() { return 0; }
} a;
struct B : A { } b;
cout << &b;
will call A::operator&();
|
|
| Back to top |
|
 |
Howard Guest
|
Posted: Fri Apr 29, 2005 2:18 pm Post subject: Re: Predefined class member functions and inheritance |
|
|
"Ron Natalie" <ron (AT) spamcop (DOT) net> wrote
| Quote: | lovecreatesbeauty wrote:
Scott Meyers says that there are 6: (1)default constructor, (2)copy
constructor, (3)destructor, (4)assignment operator, (5)address-of
operator (non-const), (6)address-of operator (const), in `Effective
C++, 2nd` item 45.
If Scott actually says what you say, he's wrong. The only FUNCTIONS
provided are the default constructor, the copy constructor, the
destructor, and the copy-assignment operator.
|
Scott does not say that, at least not there. I've just re-read item 45, and
he only talks about those four functions. I don't know where the OP got the
info about those two operators from, but it's not from item 45 in Effective
C++.
-Howard
|
|
| Back to top |
|
 |
lovecreatesbeauty Guest
|
Posted: Thu May 19, 2005 3:34 am Post subject: Re: Predefined class member functions and inheritance |
|
|
The following changes were made for the eleventh printing of the book.
These changes apply to your copy of Effective C++, Second Edition only
if you have one of the first ten printings.
! 2/10/00 ic 212 A class declaring no operator& function(s) 9/10/01
cxh 213 does NOT have them implicitly declared. Rather,
245 compilers use the built-in address-of operator
246 whenever "&" is applied to an object of that
type. This behavior, in turn, is technically
not an application of a global operator&
function. Rather, it is a use of a built-in
operator.
I eliminated mention of operator& as an
automatically generated function and adjusted the
index to eliminate entries for the removed
material.
http://www.aristeia.com/BookErrata/ec++2e-errata_frames.html
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|