编译器错误 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));
}