Idea: Lazy upcasting
Marcin Kuszczak
aarti at interia.pl
Tue Mar 27 15:38:05 PDT 2007
>
> How about:
>
.....
>
> That should already work.
>
> Cheers,
>
> Reiner
I put into my compiler:
interface Storage {
Storage param1(int);
}
abstract class StorageImpl(T) : Storage {
static assert(is(typeof(this) == T));
T param1(int p1)
{
this.p1 = p1;
return cast(T)this;
}
private int p1;
}
class SpecificStorage : StorageImpl!(SpecificStorage) {
SpecificStorage param2(bool p2) {
this.p2 = p2;
return this;
}
private bool p2;
}
void main() {
auto c = (new SpecificStorage).param1(4).param2(true);
writefln(SpecificStorage.p1, " --- ", SpecificStorage.p2);
}
... and get errors using DMD 1.009 on Linux:
covariance.d(5): class covariance.StorageImpl!(SpecificStorage).StorageImpl
unable to resolve forward reference in definition
covariance.d(16): class covariance.SpecificStorage unable to resolve forward
reference in definition
Errors on declaration of "class StorageImpl(T)" and "class SpecificStorage".
To say true I don't know why they appear - IMHO it should compile. Maybe
it's bug?
--
Regards
Marcin Kuszczak (Aarti_pl)
-------------------------------------
Ask me why I believe in Jesus - http://zapytaj.dlajezusa.pl (en/pl)
Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/
-------------------------------------
More information about the Digitalmars-d
mailing list