473,769 Members | 1,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 sStatusBarPanel s {
UINT Panels;
UINT Indicators[3];
HICON EnabledIcons[3];
HICON DisabledIcons[3];
UINT EnabledToolTips[3];
UINT DisabledToolTip s[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 3939
"matro" <ma***@despamme d.com> wrote...
I have the following struct in my class:

class CTbStDialog : public CDialog
{
public:

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

struct sStatusBarPanel s {
UINT Panels;
UINT Indicators[3];
HICON EnabledIcons[3];
HICON DisabledIcons[3];
UINT EnabledToolTips[3];
UINT DisabledToolTip s[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 'StatusBarPanel s' 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 'StatusBarPanel s' from a function that
returns an sStatusBarPanel s object, but it may be more hassle than it's
worth:

CTbStDialog::sS tatusBarPanels someFuncThatRet urnsIt() {
static CTbStDialog::sS tatusBarPanels panels =
{ 3, { .... // your stuff
};
return panels;
}

CTbStDialog::CT bStDialog(...)
: ...
, StatusBarPanels (someFuncThatRe turnsIt())
...

Victor
Jul 22 '05 #2

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

Similar topics

21
12961
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: if(ereg("Win", getenv("HTTP_USER_AGENT"))) $visos = "Windows"; elseif((ereg("Mac", getenv("HTTP_USER_AGENT"))) || (ereg("PPC",
1
4157
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 tried prefixing them with BASE:: but to no avail. Still it's ok when I set them in the construtor body, not the init list. Does this mean that it's a small advantage of the initialization inside the constructor over initialization in the init...
13
4742
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
7099
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 string literal.
8
8931
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. Like, for instance the Objective-C method: +(void)initialize Which has the following characteristics: It is guaranteed to be run
23
3663
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 the built-in types, the value is usually garbage. Is this right? However, I'm a bit confused about value-initialization, when does it happen, and what kind of values are assigned to objects?
4
3713
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 value-initialization. I think default-init calls default constructor for class objects and sets garbage values to PODs. Value-init also calls default constructor for class objects and sets 0s to POD types. This is what I've learned from the books (especially...
8
5942
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 some functions. I have defined them in the following manner: typedef struct trans Transient; typedef struct sats Satellites;
15
7871
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
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.