473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

initialization with curly brackets for class struct members

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.
Jul 22 '05 #1
1 3912
"matro" <ma***@despammed.com> 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
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: deko | last post by:
Do I need to use curly brackets in PHP if .. else statements? other constructs? Does it matter? What are Best Practices? Why? thanks in advance... This seems to work WITHOUT curly brackets:...
1
by: Jacek Dziedzic | last post by:
Hi! A) Why isn't it possible to set a member of the BASE class in an initialization list of a DERIVED class constructor (except for 'calling' the base constructor from there, of course)? I even...
13
by: Jayw710 | last post by:
hi all, this should be basic, but I can't seem to get the right syntax. i have a struct struct PTStruct { int x; int y;
20
by: Petter Reinholdtsen | last post by:
Is the code fragment 'char a = ("a");' valid ANSI C? The problematic part is '("a")'. I am sure 'char a = "a";' is valid ANSI C, but I am more unsure if it is allowed to place () around the...
8
by: Per Bull Holmen | last post by:
Hey Im new to c++, so bear with me. I'm used to other OO languages, where it is possible to have class-level initialization functions, that initialize the CLASS rather than an instance of it....
23
by: Jess | last post by:
Hello, I understand the default-initialization happens if we don't initialize an object explicitly. I think for an object of a class type, the value is determined by the constructor, and for...
4
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
8
by: Sheldon | last post by:
Hi, Can anyone help with this problem with setting up nested structures and initializing them for use. I have created several structs and placed them in a super struct that I will then pass to...
15
by: akomiakov | last post by:
Is there a technical reason why one can't initialize a cost static non- integral data member in a class?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.