This documentation is archived and is not being maintained.

Compiler Error C2680

'type' : invalid target type for name

A casting operator tried to convert to a type that is not a pointer or reference. The dynamic_cast operator can be used only for pointers or references.

The following sample generates C2680:

// C2680.cpp
class A { virtual void f(); };
class B : public A {};

void g(B b)
{
    A a;
    a = dynamic_cast<A>(b);   // C2680
}

When using Managed Extensions for C++, you may also see C2680:

// C2680b.cpp
// compile with: /clr /LD
// to resolve, only declare the properties in class
#using <mscorlib.dll>
using namespace System::Collections;
namespace ProConn 
{
  public __gc class A;
  public __gc class B : public ArrayList 
  {
    __property ProConn::A* get_A(int index) {
      return dynamic_cast<ProConn::A*>(this->get_Item(index));  // C2680
    }
    __property void set_A(int index, ProConn::A* value) {
      this->set_Item(index, value);
    }
  };
  public __gc class A { String* s; };
}
/*
ProConn::A * B::get_A( int index ) {
  return dynamic_cast< ProConn::A * >( get_Item( index ));
} 
void B::set_A( int index, ProConn::A * value ) {
  set_Item( index, value );
}
*/
Show: