A strange operate =
Added by sambsp over 4 years ago
In continent.cpp, function setup(), there is a sentence like following:
CContinentParameters::operator = (pCS->Continent);
My question:
1、As I know before, if we use operator=, we should type a "left value", and a "right value". Let the operator = just "between" these 2 values. AND,
2、If we use operator overloading, we must declare that operator in class, but in class CContinentParameters, there isn't a declaration of "operator=".
Seems it's an expression extend my learned and my imagination. :)
Replies (3)
RE: A strange operate = - Added by rti over 4 years ago
CContinent
inherits CContinentParameters
.
So writing in a CContinent
method
CContinentParameters::operator = ( pCS->Continent );
sets all the members of CContinent
which are inherited by CContinentParameters
to the values from pCS->Continent
.
It should be the same as:
*((CContinentParameters*)this) = pCS->Continent;
Does that help?
RE: A strange operate = - Added by rti over 4 years ago
To answer your questions... ( sorry ^^ )
1. The left value is the current instance, the right value is pCS->Continent
.
2. The operator is not overloaded, it is the default one (of the parent class).
RE: A strange operate = - Added by sambsp over 4 years ago
rti,
thank you very much. Seems I must get another cplusplus book to read, haven't found clues from <<C++ Primer Plus>> and <<C++ Primer>> before your answer, or maybe I ignored something, :)
(1-3/3)