1

.h file

generic<typename VAL_T> where VAL_T : value class,System::ValueType
    Nullable<VAL_T> Get();

.cpp file

generic<typename VAL_T> 
Nullable<VAL_T> FidField::Get()
  {
        return Nullable<VAL_T>();
  }

When i compile this code i get the following error.

error C3392: 'VAL_T': invalid type argument for generic parameter 'T' of generic 'System::Nullable', must have a public parameterless constructor

I am not getting any error in visual studio 2010(vc10) and 2012(vc110).

I am not sure where to add constructor. Can someone please help. Thanks in advance.

Update:

i see that the Nullable object interface has been changed in current .Net framework. current version:

generic<typename T>
where T : value struct, gcnew()
[SerializableAttribute]
public value struct Nullable

in vs2010:

generic<typename T>
where T : value class
public value class Nullable

So i added gcnew() which the Nullable class expects. I still get the same error.

Reference links: Nullable in current .Net framework

Nullable in .Net framework 4

1 Answer 1

0

The problem was due to generic typename changes of Nullable in .NET framework 4.5.

I made generic type to be of value struct, gcnew()

i added where VAL_T : value class,System::ValueType, gcnew() in both header and cpp files. This solved the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.