Share via


編譯器錯誤 C2594

'operator' : 從 'type1' 至 'type2' 的轉換模稜兩可

從 type1 至 type2 的轉換沒有比其他任何轉換更直接。 建議您可以使用兩種可能的解決方式來從 type1 轉換至 type2。 第一個選項是定義從 type1 至 type2 的直接轉換,第二個選項則是指定從 type1 至 type2 的轉換序列。

下列範例會產生 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));
}