Template constructor in a non-template struct.

ChrisG via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Feb 8 13:43:32 PST 2015


Hi, I couldn't find information about problem I'm having. This 
builds:

enum { Option1, Option2 }

struct boring {
   this(int Opt = Option1)(int arg1, int arg2) { ... }
}

However, I can't figure out how to instantiate that constructor. 
When I call it like this:

auto a = boring(1, 2);

The compiler doesn't seem the template constructor, only the 
non-template constructors which take a different set of 
arguments. When I call it like this:

auto a = boring!(Option1)(1, 2);

It complains that my struct isn't a template struct, which makes 
sense; however, I don't really understand how I'd differentiate a 
constructor template from a class/struct template.

Any ideas?

-Chris


More information about the Digitalmars-d-learn mailing list