template with enum parameter doesn't compile

Nicholas Wilson iamthewilsonator at hotmail.com
Fri Apr 5 14:52:34 UTC 2019


On Friday, 5 April 2019 at 14:47:42 UTC, Sjoerd Nijboer wrote:
> So the following code doesn't compile for some reason, and I 
> can't figure out why.
>
> enum MyEnum { A, B, C }
>
> class MyClass(MyEnum myEnum)
> {
>     /*...*/
> }
>
> int main()
> {
> 	MyClass!MyEnum.A a;
> }
>
> The error:  Error: template instance `MyClass!(MyEnum)` does 
> not match template declaration `MyClass(MyEnum myEnum)`
> pops up, no matter what I do.

You wrote:

> MyClass!MyEnum.A a;

Which is equivalent to

> MyClass!(MyEnum).A a;

What you want is

MyClass!(MyEnum.A) a;



More information about the Digitalmars-d-learn mailing list