Sdílet prostřednictvím


Chyba kompilátoru C2680

'type' : neplatný cílový typ pro název

Poznámky

Operátor přetypování se pokusil převést na typ, který není ukazatelem nebo odkazem. Operátor dynamic_cast lze použít pouze pro ukazatele nebo odkazy.

Příklady

Následující příklad vygeneruje 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 může nastat také v případě, že cíl není definován:

// 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);
      }
   }
};