void f(int){}
typedef void (*f_ptr)(int);
struct Functor{
void operator()(int){}
};
struct X{
operator f_ptr(){ return f; }
};
struct Y{
operator Functor(){
x(5); // works ?!
This implicitly casts x to an f_ptr and calls that. C++11 standard:
§ 13.3.1.1.2 Call to object of class type [over.call.object]
2) In addition, for each non-explicit conversion function declared in T of the form
operator conversion-type-id ( ) attribute-specifier-seqopt cv-qualifier ;[…where
conversion-type-iddenotes the type “pointer to function of(P1,...,Pn)returningR”…]
y(5); // doesn't ?!
The standard doesn't mention anything about implicit conversion to class types that overload operator() (aka functors), which implies that the compiler doesn't allow that.
You must cast it explicitly:
static_cast<Functor>(y)(5);