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. Advertising

  2. "matro" <> wrote...
    > 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
     
    Victor Bazarov, Dec 26, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. inquirydog

    call-template in curly brackets

    inquirydog, Dec 13, 2003, in forum: XML
    Replies:
    1
    Views:
    526
    Julian Reschke
    Dec 13, 2003
  2. Zain Homer

    glob and curly brackets

    Zain Homer, Apr 7, 2006, in forum: Python
    Replies:
    2
    Views:
    531
  3. STF
    Replies:
    6
    Views:
    444
  4. Ken Fine
    Replies:
    2
    Views:
    177
    Ken Fine
    Feb 24, 2004
  5. Andrew Poulos

    regexp and curly brackets

    Andrew Poulos, Dec 1, 2008, in forum: Javascript
    Replies:
    9
    Views:
    213
    Thomas 'PointedEars' Lahn
    Dec 2, 2008
Loading...

Share This Page