How does conversion operator return a value?

c++, casting, operators

Solution

The return type of `operator T()` is always `T`. It's a special case of C++.

It does not use standard function prototype syntax `T foo()` because 2 functions with the same name differing only by the return type cannot coexist (e.g. `int foo()` conflicts with `double foo()`). If this syntax is used then you can only define 1 conversion operator overload, which is undesirable.

Problem

For a class A, an integer conversion operator would look something like; ``` operator int() //Here we don't specify any return type { return intValue; } ``` How is the above function able to return a value when its return value type appears not to be specified? It doesn't appear to return "anything", but I know it's not `void`. How is this meaningful when a return type is not specified?

Original source