Struct ctor called with cast
ag0aep6g
anonymous at example.com
Tue Feb 27 21:04:59 UTC 2018
On 02/27/2018 09:59 PM, Radu wrote:
> On Tuesday, 27 February 2018 at 20:51:25 UTC, ag0aep6g wrote:
>> On 02/27/2018 09:30 PM, Radu wrote:
[...]
>>> enum Type { a };
>>> struct S(Type t = Type.a)
>>> {
>>> this(Type)(Type t)
>>> {
>>> import std.stdio;
>>> writeln("ctor called.");
>>> }
>>> }
[...]
> So the bug is that somehow the templated version makes it so there is an
> implicit void* ctor.
In your original code (quoted above), you've got a templated
constructor. The `Type` in `this(Type)(Type t)` is not the enum. It's a
template parameter of the constructor.
To get a non-templated constructor that takes a `Type` (the enum), you
have to write:
----
this(Type t) /* NOTE: Only one set of parentheses. */
{
/* ... */
}
----
More information about the Digitalmars-d-learn
mailing list