digitalmars.D.learn - template with enum parameter doesn't compile
- Sjoerd Nijboer (15/15) Apr 05 2019 So the following code doesn't compile for some reason, and I
- lithium iodate (5/11) Apr 05 2019 You are just having a little issue with operator precedence
- Sjoerd Nijboer (3/7) Apr 05 2019 That's really funny acutally.
- Nicholas Wilson (5/21) Apr 05 2019 Which is equivalent to
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. I'm quite puzzled actually
Apr 05 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.The error: Error: template instance `MyClass!(MyEnum)` does not match template declaration `MyClass(MyEnum myEnum)` pops up, no matter what I do. I'm quite puzzled actuallyYou are just having a little issue with operator precedence there. Your code attempts to get the member `A` from `MyClass!MyEnum`, if you add braces around it, it'll work just fine `MyClass!(MyEnum.A)`.
Apr 05 2019
On Friday, 5 April 2019 at 14:52:05 UTC, lithium iodate wrote:You are just having a little issue with operator precedence there. Your code attempts to get the member `A` from `MyClass!MyEnum`, if you add braces around it, it'll work just fine `MyClass!(MyEnum.A)`.That's really funny acutally. It works. Thank you!
Apr 05 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 toMyClass!(MyEnum).A a;What you want is MyClass!(MyEnum.A) a;
Apr 05 2019