Condividi tramite


Errore del compilatore C2179

'type': un argomento attributo non può usare parametri di tipo

Osservazioni:

Un parametro di tipo generico viene risolto in fase di esecuzione. Tuttavia, un parametro di attributo deve essere risolto in fase di compilazione. Pertanto, non è possibile usare un parametro di tipo generico come argomento per un attributo.

Esempio

L'esempio seguente genera l'errore 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;
};