On Wednesday, 8 January 2020 at 08:26:51 UTC, user1234 wrote:
class Example
{
    @disable this() { pragma(msg, "not allowed..."); }
}

void main()
{
    new Example();
}

outputs:

not allowed...
/tmp/temp_7F8C65489550.d(12,5): Error: constructor `runnable.Example.this` cannot be used because it is annotated with `@disable`

However, it will print that message even if the constructor is never called. If you make the constructor a template instead, you will only get the message when someone attempts to use the default constructor:

class Example
{
    @disable this()() { pragma(msg, "not allowed..."); }
}

void main()
{
    new Example();
}

Sadly, this does not work for structs, as they don't really have a default constructor, as Jonathan pointed out.

--
  Simen

Reply via email to