関数へのポインターである演算子

次の例では標準で指定された Visual C++ .NET 2003 以降で動作します :

// operator_that_is_pointer_to_function.cpp
// function style call on object will invoke user-defined conversion 
// if there is one. See secion 13.3.1.1.2 
typedef void(*ptf)();
void func()
{
}
struct S
{
   operator ptf()
   {
      return func;
   }
};

int main()
{
   S s;
   s();//operates as s.operator ptf()()
}

参照

その他の技術情報

Visual C++ .NET 2003 では、コンパイラ準拠が強化