Sealed classes - would you want them in D?

Walter Bright newshound2 at digitalmars.com
Sat May 12 15:36:56 UTC 2018


On 5/12/2018 8:18 AM, Piotr Mitana wrote:
> What I am trying to do is:


========== a.d ============

class P
{
     private this();
}

final class C1 : P { }
final class C2 : P { }

======== test.d ============

import a;

void foo()
{
     P[] twoPs = [ new C1(), new C2() ]; // works
}

class C3 : P   // fails
{
}

============================

dmd test a
Error: constructor a.P.this is not accessible from module test


More information about the Digitalmars-d mailing list