Mail Archives: djgpp/1997/09/06/12:03:12
On 3 Sep 1997, Paul Derbyshire wrote:
> How do the enum elements BINARY and so forth become members of ios, as in
> ios::, and not of some enum? Normally the :: thing only applies to member
> functions and instance variables, not to enums. Is the enum actually
> inside the class? Can a class contain structs and subclasses actually
> inside itself so they are only defined in the scope of the class, for
> naming purposes?
The enums in ios are defined within the class. As a result the enums only
exist within the class' namespace and you have to use explicit scoping to
use them, as in ios::bin. Note that binary is still a member of an
enum, called open_mode.
Any class, structure or enum contained inside another exists only inside
the namespace of the surrounding class. Therefore, it is possible to do
the following:
struct outside {
struct inside {
struct way_inside {
static int static_data;
int data;
} w_ins;
} ins;
} test_struct;
To get access to the variables static_data and data you would use, resp.:
outside::inside::way_inside::static_data = 1;
test_struct.ins.w_ins = 1;
To create instances of the inner classes you do the following:
outside::inside test_ins;
outside::inside::way_inside test_wins;
---------------
Peter Berdeklis
Dept. of Physics, Univ. of Toronto
- Raw text -