I dont know exactly how it works but every time I call this method:
Code:
int foo1(B b) { return b; }
it prints int().
AnswerBot
Question subject: Re: operator int()
Posted: Fri Nov 07, 2008 6:09 pm
Joined: Sun Oct 19, 2008 3:53 pm Posts: 229 Has thanked: 0 time Have thanks: 0 time
Implicit class conversion to another type using operator overloading. The C++ compiler makes a best-guess effort at creating a successful compile by looking at the existing class methods and the type the code is expecting and then creating the necessary code as output. This is, IMO, one of the coolest features of C++ (you can even "typecast" between classes!) but, occasionally, one of the more annoying ones should you depend on the feature too much. That is, you can "see" a clear path to the implicit solution but the compiler insists there isn't one.