Conversion Operators in C++

You can walk through that code with a debugger (and/or put a breakpoint on each of your constructors and operators) to see which of your constructors and operators is being invoked by which lines. Because you didn’t define them explicitly, the compiler also created a hidden/default copy constructor and assignment operator for your class. You … Read more

How do conversion operators work in C++?

Some random situations where conversion functions are used and not used follow. First, note that conversion functions are never used to convert to the same class type or to a base class type. Conversion during argument passing Conversion during argument passing will use the rules for copy initialization. These rules just consider any conversion function, … Read more

Conversion constructor vs. conversion operator: precedence

You do copy initialization, and the candidate functions that are considered to do the conversions in the conversion sequence are conversion functions and converting constructors. These are in your case B(const A&) operator B() Now, that are the way you declare them. Overload resolution abstracts away from that, and transforms each candidate into a list … Read more