chaining
BCS
ao at pathlink.com
Thu Feb 26 11:17:01 PST 2009
Reply to Brian,
> On Wed, 25 Feb 2009 22:08:43 +0000, BCS wrote:
>
>> template BaseT(){
>> typeof(this) foo()(int x_) {
>> this.x = x_;
>> return this;
>> }
>> }
>> class Base {
>> int x;
>> mixin BaseT!();
>> }
>> template DerivedT()
>> {
>> typeof(this) bar(int y_) {
>> return this;
>> }
>> mixin BaseT!();
>> }
>> class Derived : Base {
>> mixin DerivedT!();
>> }
> hmm.. is that really the best way? if the function has 10 lines of
> code and is mixed into to 15 classes thatll give me 15 times the code
> for that one function i think. also gets a bit tricky when i want to
> override some of the functions. (by using another class in between
> base and derived?). i think i need a new plan..
>
you could stuff all the functonality into non-mixedin functions and only
mix in shells
template DerivedT()
{
typeof(this) bar(int y_) {
do_bar(y_);
return this;
}
}
More information about the Digitalmars-d-learn
mailing list