Jos Timanta Tarigan wrote:
> Hi, 
> 
> I got a question. I have a class B that has this method:
> 
> operator int()
> {
>    std::cout << "int()" << std::endl;
>    return i;
> }
> 
> I dont know exactly how it works but every time I call this method:
> 
> int foo1(B b)
> {
>    return b;
> }
> 
> it prints int().
> 
> Any1 know?

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.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to