Cast Object - get null

Jonathan M Davis jmdavisProg at gmx.com
Wed Apr 18 23:56:03 PDT 2012


On Thursday, April 19, 2012 08:25:13 Namespace wrote:
> Wow, many thanks for your trouble. Now it works as aspected.
> I only need
> 
> T opCast(T)() const if(isImplicitlyConvertible!(typeof(this), T))
> {
> 	return this;
> }
> 
> to work.
> 
> But if i try to cast to a const like this
> const Vector2s vs_ = cast(Vector2s)(vf);
> 
> I get a long list of compiler errors.
> Thereby it's petty if i have only
> 
> T opCast(T)() const if(isImplicitlyConvertible!(typeof(this), T))
> {
> 	return this;
> }
> 
> or additional the const variant
> 
> const(T) opCast(T)() const
> if(isImplicitlyConvertible!(typeof(this), const T)) {
> 	return this;
> }


Well, if the function is const (which makes this const), since you're 
returning this, the return type must be const. It can only return non-const if 
the function isn't const. That's why I suggested having both overloads.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list