alias base._ctor is not as powerful as i thought

DavidL Davidl at 126.com
Sun Sep 9 00:54:28 PDT 2007


在 Sun, 09 Sep 2007 12:37:03 +0800,DavidL <Davidl at 126.com> 写道:

> 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.
>

:D the members are initialized. so the cast could be killed maybe ? then  
we can say byebye to trivial this(){super()}


-- 
使用 Opera 革命性的电子邮件客户程序: http://www.opera.com/mail/



More information about the Digitalmars-d mailing list