编译器错误 C2680
“type”:名称的目标类型无效
强制转换运算符尝试了转换为不是指针或引用的类型。 dynamic_cast 运算符只能用于指针或引用。
下面的示例生成 C2680:
// C2680.cpp
// compile with: /c
class A { virtual void f(); };
class B : public A {};
void g(B b) {
A a;
a = dynamic_cast<A>(b); // C2680 target not a reference type
a = dynamic_cast<A&>(b); // OK
}
如果未定义目标,也可能发生 C2680:
// C2680b.cpp
// compile with: /clr /c
// C2680 expected
using namespace System::Collections;
// Delete the following line to resolve.
ref class A; // not defined
// Uncomment the following line to resolve.
// ref class A{};
public ref class B : ArrayList {
property A^ C[int] {
A^ get(int index) {
return dynamic_cast<A^>(this->default::get(index));
}
void set(int index, A^ value) {
this->default::set(index, value);
}
}
};