"Boris" <bo***@gtemail.netwrote in message
news:op***************@burk.t-com.ne.jp...
On Tue, 12 Jun 2007 14:38:53 +0900, Ben Voigt [C++ MVP]
<rb*@nospam.nospamwrote:
>"Boris" <bo***@gtemail.netwrote in message
news:op***************@burk.t-com.ne.jp...
>>I have a class which should like this ideally:
generic <typename T>
public ref class ManagedClass
{
T ^managedMember;
UnmanagedClass<U*unmanagedMember;
};
I actually would like to specify the type U depending on the type T. As
far as I understand there is no direct support for this in C++/CLI (I
can't use U as a parameter for the generic for example)? Did anyone
solve this problem before and can recommend a solution? As ManagedClass
will be
Template instantiation is done by the C++ compiler, generic
instantiation for value types by the JIT, and generics are not
instantiated for ref types.
Thanks for your reply, Ben! As it turns out I can actually make the class
template-only (at least for my purpose as I know at compile time which
types depend on what). I'm not so sure anymore if my question made much
sense at all as the unmanaged type U can't really depend on the managed
type T if U is provided at compile time but T at runtime?
I missed that part. Actually, U can depend on T only via the generic
mechanism. For example, U could be
System::Collections::Generic::IEnumerable<T>^.... and I'm not sure whether
you there is support for generic generic in the same way as template
templates. I don't think so, I think U would have to be explicitly stated
by the user.
What I'm talking about, is of course:
generic <typename T, typename U>
/* questionable syntax here */ where U :
System::Collections::Generic::IEnumerable<T>^
public ref class ManagedClass
{
T ^managedMember;
UnmanagedClass<U*unmanagedMember;
};
ManagedClass<Form, List<Form>is ok
ManagedClass<string, Set<string>is ok
ManagedClass<int, cli::array<int>is ok
But of course, then U isn't an unmanaged type. Wonder if you could use
generics in an unmanaged type... I think gcroot<Tis a template, not
generic.
>
Boris
>[...]