Compartir a través de


Error del compilador C2179

'type': un argumento de atributo no puede utilizar parámetros de tipo

Los parámetros de tipo genéricos se resuelve en tiempo de ejecución. Sin embargo, los parámetros de atributo debe resolverse en tiempo de compilación. Por consiguiente, no se puede usar un parámetro de tipo genérico como argumento para un atributo.

Ejemplo

El ejemplo siguiente genera el error C2179.

// C2179.cpp
// compile with: /clr
using namespace System;

public ref struct Attr : Attribute {
   Attr(Type ^ a) {
      x = a;
   }

   Type ^ x;
};

ref struct G {};

generic<typename T>
public ref class Z {
public:
   Type ^ d;
   [Attr(T::typeid)]   // C2179
   // try the following line instead
   // [Attr(G::typeid)]
   T t;
};