请考虑以下代码:
public ref class Factory
{
public:
generic <typename T> where T : value class, System::ValueType
static System::Nullable<T> Create()
{
return System::Nullable<T>();
}
};
Visual C++ 2008 吐出以下错误:
error C2440: 'return' : cannot convert from 'System::Nullable<T>' to 'System::Nullable<T>'
如果我用用户定义的类型替换“System::Nullable”类型,它就可以正常工作:
generic <typename T> where T : value class, System::ValueType
public value class MyType
{ };
public ref class Factory
{
public:
generic <typename T> where T : value class, System::ValueType
static MyType<T> Create()
{
return MyType<T>();
}
};
这是某种 VC++ 错误,还是我在这里遗漏了什么?