Will an implicit conversion function be called to express itself?

Suppose that I myself define the implicit conversion function:

#include <iostream> class Foo { public: operator Foo() { std::cout << "wha??\n"; return Foo(); } }; void f(Foo f) {} int main() { Foo foo; f(foo); } 

Why should I determine this? Well, I would never write it directly, but this could happen with a template instance in the template class that I am writing. If this happens, I hope that the definition of the transform function does not work effectively and that it is actually impossible to call.

The above program doesn't print anything (that's great). Are there any circumstances under which this conversion function will actually be called?

+7
c ++
source share
1 answer

This is correct, but never called, due to n3376 12.3.2 / 1

the conversion function is never used to convert an object (possibly cv-qualified) to (possibly with cv qualification) the same type of object (or a reference to it)

+11
source share

All Articles