auto & class members

Robert M. Münch robert.muench at saphirion.com
Sun May 20 17:46:14 UTC 2018


On 2018-05-20 17:40:39 +0000, Robert M. Münch said:

> Hi Jonathan, great! This got me a step further. So I can declare my 
> member now. But I get an implict cast error when I try:
> 
> class a {
> 	... myStream;
> }
> 
> class b {
> 	typeof(a.myStream.filter!(x => x == myMessage)) mySubStream;
> }
> 
> void myFunc() {
> 	a myA = new a();
> 	b myB = new b();
> 
> 	myB.mySubstream = myA.myStream.filter!(x => x == myMessage);
> }
> 
> This gives (unnecessary stuff stripped):
> 
> Error: cannot implicitly convert expression filter(...) of type 
> app.myFunc.filter!(x => x == myMessage) to app.b.filter!(x => x == 
> myMessage)

Answering myself: Using an alias helps.

alias typeof(a.myStream.filter!(x => x == myMessage)) myMessageType;

class b {
	myMessageType mySubStream;
}

void myFunc() {
	a myA = new a();
	b myB = new b();

	myB.mySubstream = cast(myMessageType)myA.myStream.filter!(x => x == 
myMessage);
}

But I still don't understand why I can't write things explicitly but 
have to use an alias for this.

-- 
Robert M. Münch
http://www.saphirion.com
smarter | better | faster



More information about the Digitalmars-d-learn mailing list