Re: =?UTF-8?B?Kz0=?= operation
This is a MIME GnuPG-signed message. If you see this text, it means that
your E-mail or Usenet software does not support MIME signed messages.
The Internet standard for MIME PGP messages, RFC 2015, was published in 1996.
To open this message correctly you will need to install E-mail or Usenet
software that supports modern Internet standards.
--=_mimegpg-commodore.email-scan.com-2581-1213461336-0001
Content-Type: text/plain; format=flowed; charset="US-ASCII"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit
foolsmart2005@gmail.com writes:
for += operation, my code is:
ComplexNum ComplexNum::operator += (const ComplexNum& rhs) const
{
ComplexNum ans;
ans.real += rhs.real;
ans.imaginary += rhs.imaginary;
return ans;
}
here is lecturer's comment:
+= should be different. a += b means a = a + b
Your lecturer should've also told you that your results are undefined since
the contents of the ans object are, apparently, not initialized. Your +=
operation on ans's members are applied to, apparently, uninitialized members
of this object. This would be the same as writing:
int x;
x += 4;
Obviously, the results of this are undefined.
therefore *this object (i.e. a) should be updated with the answer.
Correct.
Do anyone know how to write += operation?
Yes, but why don't you try to figure this out yourself. Look around, there
are plenty of examples of assignment operators for other classes. Here are
two free clues:
1) operator += modifies this object, therefore it cannot be a const
function (well, it can be, but you're not there, yet).
2) The assignment operator, be it operator =(), operator +=(), operator
-=(), or anything else, traditional does not return another instance of the
object, but rather a reference to this, modified, object.
--=_mimegpg-commodore.email-scan.com-2581-1213461336-0001
Content-Type: application/pgp-signature
Content-Transfer-Encoding: 7bit
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
iEYEABECAAYFAkhT81gACgkQx9p3GYHlUOKqFgCfTH21mCsaDHj6G3oDZ8WKtuw9
VMMAn3BxWQphDs5vEcoBgvba0JX5/fcu
=KvB4
-----END PGP SIGNATURE-----
--=_mimegpg-commodore.email-scan.com-2581-1213461336-0001--