3 ms·
I’ve heard it that implicit conversion is a specialization of copy construction. So you can still use explicit Foo (const Foo& other) if you wish to force all c
by raganwald 15y ago
I’ve heard it that implicit conversion is a specialization of copy construction. So you can still use explicit Foo (const Foo& other) if you wish to force all construction of Foos to use the new keyword and not to be passed by value. But I’m certainly willing to accept the suggestion that the two are distinct, in which case my understanding is that the explicit keyword blocks implicit conversion (as described in the story and in your example) and I understand that it also blocks implicit copy construction.
- ryanmolden 15y agoAh, that makes sense. Though technically you don't have to use the new keyword unless you want a heap allocated instance, something like HandleTheFoo(Foo(5)); or even HandleTheFoo(Foo(otherFoo)); is perfectly cromulent with the constructor being marked explicit. But that is just me engaging in terminological quibbling, I get what you meant/said in spirit and don't disagree that people asking questions they don't have a deep understanding of themselves can only lead to fail.
- raganwald 15y agoThanks for the kind words. And the reminder about stack variables!!! I wasn’t trying to suggest that Ted didn’t have deep knowledge of C++, as we can see his fictional knowledge is far better than my distant memories. I was trying to suggest that he was engaging in copy-and-paste interviewing, and that it’s a bad idea for all of the same reasons copy-and-paste coding is a bad idea :-)