T
Tony Maresca
I'm having a hard time understanding why I get
the following error with the code shown.
Can someone explain?
public ref class Class1
{
};
generic<typename T> where T: Class1, gcnew()
public ref class Gen
{
public:
Gen() {}
T GetVal(bool condition)
{
if( condition )
return gcnew T();
else
return nullptr; // <----- Error: C2440
}
};
public ref class test
{
public:
test()
{
Gen<Class1^> gen = gcnew Gen<Class1^>();
Class1^ x1 = nullptr;
Class1^ x2 = gcnew Class1();
Class1^ x3 = gen->GetVal(false);
}
};
// C2440: 'return' : cannot convert from 'nullptr' to 'T'
--
Tony M.
the following error with the code shown.
Can someone explain?
public ref class Class1
{
};
generic<typename T> where T: Class1, gcnew()
public ref class Gen
{
public:
Gen() {}
T GetVal(bool condition)
{
if( condition )
return gcnew T();
else
return nullptr; // <----- Error: C2440
}
};
public ref class test
{
public:
test()
{
Gen<Class1^> gen = gcnew Gen<Class1^>();
Class1^ x1 = nullptr;
Class1^ x2 = gcnew Class1();
Class1^ x3 = gen->GetVal(false);
}
};
// C2440: 'return' : cannot convert from 'nullptr' to 'T'
--
Tony M.