initialization with curly brackets for class struct members

M

matro

hi there,

I have the following struct in my class:

class CTbStDialog : public CDialog
{
public:

int fooVar, fooVar2;
... //other foo variables...

struct sStatusBarPanels {
UINT Panels;
UINT Indicators[3];
HICON EnabledIcons[3];
HICON DisabledIcons[3];
UINT EnabledToolTips[3];
UINT DisabledToolTips[3];
UINT Styles[3];
UINT Widths[3];
} StatusBarPanels;
}

how can I initialize StatusBarPanels without referencing each of its
members?

I'd like to use an init such as StatusBarPanels={ 3, {ID_SEPARATOR....
.....} } but I don't know where to place such initialization: it seems it
only works when initializing function member variables, and not for class
member ones.

as a matter of fact, it seems a compiler semantics limitation.

can you help me?

thank you.
 
V

Victor Bazarov

matro said:
I have the following struct in my class:

class CTbStDialog : public CDialog
{
public:

int fooVar, fooVar2;
... //other foo variables...

struct sStatusBarPanels {
UINT Panels;
UINT Indicators[3];
HICON EnabledIcons[3];
HICON DisabledIcons[3];
UINT EnabledToolTips[3];
UINT DisabledToolTips[3];
UINT Styles[3];
UINT Widths[3];
} StatusBarPanels;
}

how can I initialize StatusBarPanels without referencing each of its
members?

I'd like to use an init such as StatusBarPanels={ 3, {ID_SEPARATOR....
....} } but I don't know where to place such initialization: it seems it
only works when initializing function member variables, and not for class
member ones.

No, you can only do such initialisation as part of the initialisation
for an entire CTbStDialog object.
as a matter of fact, it seems a compiler semantics limitation.

can you help me?

I am not sure what kind of help you need. Since 'StatusBarPanels' is
a data member, the only place where you can _initialise_ it is the
initialisation list of the constructor for CTbStDialog (which you didn't
show). In the member initialisation list no {} forms are allowed. You
could try initialising your 'StatusBarPanels' from a function that
returns an sStatusBarPanels object, but it may be more hassle than it's
worth:

CTbStDialog::sStatusBarPanels someFuncThatReturnsIt() {
static CTbStDialog::sStatusBarPanels panels =
{ 3, { .... // your stuff
};
return panels;
}

CTbStDialog::CTbStDialog(...)
: ...
, StatusBarPanels(someFuncThatReturnsIt())
...

Victor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top