共用方式為


編譯器警告 (層級 1) C4927

不合法的轉換;已隱含套用多個使用者定義轉換

一個以上的使用者定義轉換會隱含地套用至單一值 -- 編譯器找不到明確的轉換,但確實找到所使用的轉換。

下列範例會產生 C4927:

// C4927.cpp
// compile with: /W1
struct B
{
   operator int ()
   {
      return 0;
   }
};

struct A
{
   A(int i)
   {
   }

   /*
   // uncomment this constructor to resolve
   A(B b)
   {
   }
   */
};

A f1( B& b)
{
   return A(b);
}

B& f2( B& b)
{
   return b;
}

A f()
{
   B b;
   return A(b);   // ok
   return f1(b);  // ok
   return b;      // C4927
   return B(b);   // C4927
   return f2(b);  // C4927
}

int main()
{
   B b;
   A a = b;
   A a2(b);
}