Mixin a constructor ?

Jacob Carlborg doob at me.com
Sat Sep 19 13:25:54 PDT 2009


On 9/19/09 20:55, Christopher Wright wrote:
> Jacob Carlborg wrote:
>> Is it supposed to possible to mixin a constructor? The code below
>> doesn't compile. The error: is "main.d(23): Error: constructor
>> main.A.this() does not match parameter types (int)
>> main.d(23): Error: expected 0 arguments, not 1"
>
> A template mixin introduces a new scope. This is pretty annoying in some
> cases. More often, it is convenient. Since the constructor is not in the
> same scope as the class, it might be causing problems.

The problem only seems to be when I'm having constructors both in the 
template and in the class.

> If you didn't introduce a new scope by default, it'd be easy enough to
> add it in the template or around the mixin:
>
> template MixMeIn()
> {
> int imInUrScope;
> {
> int imOuttaUrScope;
> }
> }
>
>
> Additionally, the difference would be easily detectable, because symbol
> collision would cause the code to fail to compile. Unless the mixin adds
> a function overload and you pass the address of the overload set
> somewhere, and now you're passing the wrong overload...which is an old
> problem for D, aggravated by D's property syntax, and unlikely to be
> fixed soon.




More information about the Digitalmars-d mailing list