alias base._ctor is not as powerful as i thought
DavidL
Davidl at 126.com
Sat Sep 8 21:37:03 PDT 2007
class base
{
int j;
this(char[] hello){}
this(int k){}
this(){}
}
class inherit:base
{
int k;
float myfloat;
alias base._ctor _ctor;
this(){}
void show(){writefln("%d%d",k,j);}
}
void main()
{
base uber = new inherit(3);
(cast(inherit)uber).k=40;
// assertion fails here
assert((cast(inherit)uber).myfloat == float.nan); // it's sad it's not NAN
}
Yet, after some though for a while, it's the correct behavior to force
users to cast & thus
no RAII for derived class members. But this makes alias base._ctor _ctor;
some what unusable
If there's any way of making it smarter would be nicer :D
like autogen wrapper for alias _ctor with
this(protocal)
{
super.this
}
current behavior is a bit low level, and it could hide some problems, if
users're not aware of
the current behavior.
--
使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/
More information about the Digitalmars-d
mailing list