共用方式為


編譯器錯誤 C2594

'operator' :從 'type1' 到 'type2' 的模棱兩可轉換

從 type1 到 type2 的任何轉換都比任何其他類型都更直接。 我們建議兩個可能的解決方案,從 type1 轉換成 type2。 第一個選項是定義從 type1 到 type2 的直接轉換,第二個選項是指定從 type1type2 的轉換序列。

下列範例會產生 C2594。 錯誤的建議解決方法是一連串的轉換:

// C2594.cpp
// compile with: /c
struct A{};
struct I1 : A {};
struct I2 : A {};
struct D : I1, I2 {};

A *f (D *p) {
   return (A*) (p);    // C2594

// try the following line instead
// return static_cast<A *>(static_cast<I1 *>(p));
}