digitalmars.D.learn - Public constants and types in class
- Herbert (2/2) Jan 27 2020 How can a class provide it's users with named constants, enums,
- Steven Schveighoffer (15/17) Jan 27 2020 Just declare them inside the class. They then go inside the class
How can a class provide it's users with named constants, enums, types, structs and not just member functions?
Jan 27 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
Jan 27 2020