For the following code
interface class I{};
public ref struct R1 : I
{
R1(R1%){}
R1(){}
};
generic <class T> // if you replace it with template, it works.
void f(T t)
{
I ^hi = t; // error in this line
}
int main()
{
R1 ^obj;
I ^hi = obj;
f(obj);
}
t.cpp
t.cpp(11) : error C2440: 'initializing' : cannot convert from 'T' to 'I ^'
No user-defined-conversion operator available, or
Conversion from generic type not allowed
If I replace generic with template it works fine. Can anyone tell what's
going on?
Thanks,
Kapil
Ben Schwehn - 20 Sep 2004 11:20 GMT
> If I replace generic with template it works fine. Can anyone tell what's
> going on?
You will need to constraint the generic type parameter to implement
inter face I like this:
generic <class T> where T:I
void f(T t)
{
I ^hi = t;
}
have a look at the differences between generics and templates described
here:
http://msdn2.microsoft.com/library/sbh15dya.aspx
hth

Signature
Ben
http://bschwehn.de