help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

struct member initialization


From: ferns-paanakker
Subject: struct member initialization
Date: 2 Jan 2007 02:54:01 -0800
User-agent: G2/1.0

Hi g++ experts,

First of all, happy new year and the best wishes for 2007!
I get a warning in g++ when I use a struct which I don't initialize in
the member initialization, but in the constructor itself.
To correct this I want to perform member
initialization, but I have no idea how to do this correctly.
Some example code (from the top of my head):

typedef struct MyDate
{
unsigned short year;

unsigned short month;
unsigned short day;
} MyDate;


class
{
public:
        MyTest();
private:
        MyDate date;
}

void MyTest::MyTest() :
  date.year(0) -> this doesn't work. What syntax should i use?
{
  /*  This works, but generates the warning because date is not
initialized in the member initialization
        date.year = 0;
        date.month = 0;
        date.day = 0;
  */
}

I hope someone can help.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]