Public constants and types in class

Steven Schveighoffer schveiguy at gmail.com
Mon Jan 27 20:13:21 UTC 2020


On 1/27/20 3:05 PM, Herbert wrote:
> How can a class provide it's users with named constants, enums, types, 
> structs and not just member functions?

Just declare them inside the class. They then go inside the class 
namespace, but are not strictly part of the class instance itself.

e.g.:

class C
{
   enum Enum { one, two, three}
   struct S { int x; int y; }
}

C.Enum e = C.Enum.one;
C.S s = C.S(1, 2);

// can also access the namespace via an instance:
C instance;
instance.Enum e = instance.Enum.one;

-Steve


More information about the Digitalmars-d-learn mailing list