Windows 7, Visual Studio 2008 C++
Assignment operator overload
Horton's book VS C++ 2008 provides this example of operator overloading for classes:
where motto1 through3 are instances of class CMessage and contain member function of type char * for an example. Then he presents the following line of code that should work properly:
This makes no sense to me. I understand that for integers:
will result in y being set to 3 then x being set to y. But the parenthized version makes no sense. I wrote it up and ran it as:
x wound up with 7, while y and z were unchanged. The debugger would not step into that line of code so I cannot state what happend with certainty. But, it appears that x gets the value of y, then x gets the value of z.
And the question is: Horton probably had a reason for putting this in the text. What might that reason be?
We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)
Assignment operator overload
Horton's book VS C++ 2008 provides this example of operator overloading for classes:
Code:
motto1 = motto2 = motto3;
Code:
(motto_1 = motto2) = motto3;
Code:
x = y = 3
Code:
int x = 1; int y = 3; int z = 7;
(x = y ) = z;
And the question is: Horton probably had a reason for putting this in the text. What might that reason be?
We need to know what a dragon is
before we study its anatomy.
(Bryan Kelly, 2010)