• Advertisement

# [.net] Generic classes in mixed C# and C++/CLI VS2010 solution

This topic is 2826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hi, I have a trivial .NET 4.0 C# project, consisting of ICSharpInterface.cs:
namespace CSharp {
public interface ICSharpInterface<T> where T : struct {
}
}


According to the documentation, "where T : struct" constrains T to be a value type. I also have a trivial .NET 4.0 C++/CLI project that references the C# project. It consists of CPPImplementation.h and CPPImplentation.cpp:
#pragma once

namespace CPlusPlus {
generic <typename T> where T : value class
public ref class CPPImplementation : CSharp::ICSharpInterface<T>
{
};
}


#include "CPPImplementation.h"


According to the documentation, "where T : value class" constrains T to be a value type. When I attempt to build the solution, it fails as follows when compiling CPPImplementation.cpp: Error 1 error C3214: 'T' : invalid type argument for generic parameter 'T' of generic 'CSharp::ICSharpInterface', does not meet constraint 'System::ValueType ^' y:\develop\vs2010\test\cppimplementation\CPPImplementation.h 5 1 CPPImplementation Any ideas who or what is at fault here? I find it odd that it wants T to be "System::ValueType^" instead of "System::ValueType". Maybe the definition of "value type" is different in C++/CLI and C#, even though they both run on top of .NET ? thanks Tom

#### Share this post

##### Share on other sites
Advertisement

• Advertisement