digitalmars.D.bugs - Another template oddity?
- David Medlock (22/23) Dec 09 2004 template TVector(T,uint SZ)
- Ben Hinkle (29/52) Dec 09 2004 The return type of MyFunct is Vector but it is assigning to a variable o...
template TVector(T,uint SZ)
{
class Vector
{
T[SZ] values;
Vector MyFunct(T f)
{
return new Vector();
}
}
}
class V3f : TVector!(float,3).Vector {}
void main( char[][] arg )
{
V3f v = new V3f();
v = v.MyFunct(100.0f);
}
...
compiler gives me:
"C:\dmd\bin\dmd.exe" -debug -c E:\proj\temp\bug2.d
E:\proj\temp\bug2.d(23): cannot implicitly convert expression
cast(Vector )(v).MyFunct(100) of type Vector to V3f
Should not this conversion be implicit?
Dec 09 2004
"David Medlock" <amedlock nospam.org> wrote in message
news:cp9ng4$c9p$1 digitaldaemon.com...
template TVector(T,uint SZ)
{
class Vector
{
T[SZ] values;
Vector MyFunct(T f)
{
return new Vector();
}
}
}
class V3f : TVector!(float,3).Vector {}
void main( char[][] arg )
{
V3f v = new V3f();
v = v.MyFunct(100.0f);
}
...
compiler gives me:
> "C:\dmd\bin\dmd.exe" -debug -c E:\proj\temp\bug2.d
E:\proj\temp\bug2.d(23): cannot implicitly convert expression
cast(Vector )(v).MyFunct(100) of type Vector to V3f
Should not this conversion be implicit?
The return type of MyFunct is Vector but it is assigning to a variable of
type V3f, which is not allowed without a cast. It is like
class Foo;
class Bar : Foo;
...
Bar x;
...
x = new Foo;
...
But this is allowed:
Foo y;
y = new Bar;
By the way, your example can be shortened to:
class Vector(T,uint SZ)
{
T[SZ] values;
Vector MyFunct(T f)
{
return new Vector();
}
}
class V3f : Vector!(float,3) {}
void main( char[][] arg )
{
V3f v = new V3f();
v = v.MyFunct(100.0f);
}
Dec 09 2004








"Ben Hinkle" <bhinkle mathworks.com>