I defined a copy constructor for a class A. Due to an unfortunate macro expansion, I ended up compiling the following:
A a = a;
I (eventually) realized this results in a call to A::A(const A& rhs) with this==&rhs.
-
Why does the compiler allow this? Conceptually I would assume that since
ais declared in this statement, it wouldn't yet be available for use on the RHS. -
Should I defensively check
this==&rhswhenever I define a copy constructor?
I am using gcc version 5.4.0 with -std=c++11.
Aucun commentaire:
Enregistrer un commentaire