Sign in to follow this  
tweduk

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

Recommended Posts

tweduk    144
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


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this