www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Public constants and types in class

reply Herbert <ht softdesign.de> writes:
How can a class provide it's users with named constants, enums, 
types, structs and not just member functions?
Jan 27 2020
parent Steven Schveighoffer <schveiguy gmail.com> writes:
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