C++/CLI value class constraint won't compile. Why?
- by Simon
Hello,
a few weeks ago a co-worker of mine spent about two hours finding out why this piece of C++/CLI code won't compile with Visual Studio 2008 (I just tested it with Visual Studio 2010... same story).
public ref class Test
{
generic<class T> where T : value class
void MyMethod(Nullable<T> nullable)
{
}
};
The compiler says: Error
1 error C3214: 'T' : invalid type
argument for generic parameter 'T' of
generic 'System::Nullable', does not
meet constraint 'System::ValueType
^' C:\Users\Simon\Desktop\Projektdokumentation\GridLayoutPanel\Generics\Generics.cpp 11 1 Generics
Adding ValueType will make the code compile.
public ref class Test
{
generic<class T> where T : value class, ValueType
void MyMethod(Nullable<T> nullable)
{
}
};
My question is now. Why? What is the difference between value class and ValueType?