hi
I have a struct and one of its fields is an enumerated type as below:
enum days {MON,TUE,WED,THU,FRI,SAT, SUN }
struct myStruct
{ int number;
enum days someday;
}
is there any way to ensure that every time I create a variable of type myStruct its someday field ==MON
That is if I write
struct myStruct a;
can I be sure that immediately after this statement
a.someday==MON
is there any keyword or anything I can add. Btw I am using gnu C compiler...
10x
Automatically initialize struct ?
Try this
http://library.thinkquest.org/C008294/ud...
enum days {MON,TUE,WED,THU,FRI,SAT, SUN };
struct myStruct
{
myStruct();
int number;
enum days someday;
void init() {
number = 0;
someday = TUE;
}
};
myStruct::myStruct()
:number(0), someday(WED) {}
struct myStruct the_struct;
If it works please let me know
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment