mixed-in ctor not on par with explicit one?

Jacob Carlborg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 13 00:35:36 PST 2016


On 2016-01-13 04:32, Shriramana Sharma wrote:
> Hello. Compiling the following code:
>
> mixin template intCtor() { this(int i) {} }
> struct Test { mixin intCtor; this(string s) {} }
> void main()
> {
>      auto a = Test("hello");
>      auto b = Test(1);
> }
>
> ...gives the error:
>
> <src>(6): Error: constructor <src>.Test.this (string s) is not callable
> using argument types (int)
>
> What is the problem in calling the mixed-in ctor?

Mixed in functions are in a different overload set from the context 
where they're mixed in [1].

[1] http://dlang.org/spec/template-mixin.html - search for "Alias 
declarations can be used to overload together functions declared in 
different mixins"

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list