Unwanted conflict
Jonathan M Davis
jmdavisProg at gmx.com
Sat Jul 20 22:02:18 PDT 2013
On Sunday, July 21, 2013 05:17:03 Carl Sturtivant wrote:
> On Saturday, 20 July 2013 at 22:33:00 UTC, bearophile wrote:
> > Carl Sturtivant:
> >> What is the conflict exactly?
> >
> > Perhaps it's a bug fixed in GIT head. As workaround try:
> >
> > this()(string s)
>
> OK, but now I don't know how to call a templated constructor.
>
> void main() {
> A x = A!3(99);
> }
>
> added to the file containing the original class with the
> workaround edited in doesn't compile, and curiously the error
> message is produced twice:
>
> constr_conflict.d(9): Error: template instance A!(3) A is not a
> template declaration, it is a struct
> constr_conflict.d(9): Error: template instance A!(3) A is not a
> template declaration, it is a struct
>
> What do I need to do to make a call of this constructor call
> compile?
Templated constructors will work with IFTI (Implicit Function Template
Instantiton - i.e. where the types are inferred from the arguments), but I'm
not sure that it works when you have to explicitly instantiate them. I know
that if the type itself is templated as wel, then you're out of luck, because
the language provides no way to explicitly instantiate both (though maybe you
could do it by aliasing the explicitly instantiated templated type and then
explicitly instantiating the constructor using the alias).
I'd argue that your example should work, because the type itself isn't
templated, and the compiler should be able to determine that you're trying to
explicitly instantiate the constructor, not the type, but I don't know what
the compiler devs' stance on it would be.
I'd suggest opening a bug report: http://d.puremagic.com/issues
But if your example doesn't work, then I don't know of any to explicitly
instantiate a templated constructor.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list