Does D have too many features?
Timon Gehr
timon.gehr at gmx.ch
Sat Apr 28 13:32:04 PDT 2012
On 04/28/2012 10:02 PM, Walter Bright wrote:
> On 4/28/2012 12:36 PM, Andrej Mitrovic wrote:
>> Also there's mixin templates. What exactly is the difference between
>> mixin templates and regular templates?
>
> A mixin template is instantiated in context of the instantiation point,
> while a regular template is instantiated in the context of the template
> definition point.
>
> This becomes relevant when looking up symbols that are not defined
> within the template.
The implementation seems to disagree:
int x;
template X(){ // not a mixin template
void y(){x=2;}
}
class C{
int x;
mixin X; // picks up local 'x'
}
void main(){
auto c = new C;
c.y();
import std.stdio;
writeln(x," ",c.x); // "0 2"
}
Or am I misunderstanding your statement?
More information about the Digitalmars-d
mailing list