Nóta
Teastaíonn údarú chun rochtain a fháil ar an leathanach seo. Is féidir leat triail a bhaint as shíniú isteach nó eolairí a athrú.
Teastaíonn údarú chun rochtain a fháil ar an leathanach seo. Is féidir leat triail a bhaint as eolairí a athrú.
type declarations are only permitted at global, namespace, or class scope
Remarks
You cannot declare a generic or template class outside global or namespace scope. If you make your generic or template declarations in an include file, make sure the include file is at global scope.
Examples
The following example generates C2951:
// C2951.cpp
template <class T>
class A {};
int main() {
template <class T> // C2951
class B {};
}
C2951 can also occur when using generics:
// C2951b.cpp
// compile with: /clr /c
// OK
generic <class T>
ref class GC { };
int main() {
generic <class T> ref class GC2 {}; // C2951
}