initialization with curly brackets for class struct members

Discussion in 'C++' started by matro, Dec 26, 2003.

  1. matro

    matro Guest

    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.
     
    matro, Dec 26, 2003
    #1
    1. Advertisements

  2. No, you can only do such initialisation as part of the initialisation
    for an entire CTbStDialog object.
    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
     
    Victor Bazarov, Dec 26, 2003
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.