C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

wstring array?

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Saurabh Aggrawal
Guest





PostPosted: Wed Dec 15, 2004 1:03 pm    Post subject: wstring array? Reply with quote



Hi,

On line nos. 24, 25, 26

24: wstring cfMethods[] = {{L"setLabel"},{L""}};
25: wstring cfProperties[]= {{L"isVisible"},{L""}};
26: wstring cfEvents[] =
{{L"onLoad"},{L"onQueryTerminate"},{L"onTerminate"},{L""}};

i am getting the following errors:

cframe.cpp(24) : error C2552: 'cfMethods' : non-aggregates cannot be
initialized with initializer list
'std::basic_string<_E,_Tr,_A>' : Types with private or
protected data members are not aggregate
with
[
_E=wchar_t,
_Tr=std::char_traits<wchar_t>,
_A=std::allocator<wchar_t>
]
cframe.cpp(24) : error C2552: 'cfMethods' : non-aggregates cannot be
initialized with initializer list
'std::basic_string<_E,_Tr,_A>' : Types with private or
protected data members are not aggregate
with
[
_E=wchar_t,
_Tr=std::char_traits<wchar_t>,
_A=std::allocator<wchar_t>
]
cframe.cpp(25) : error C2552: 'cfProperties' : non-aggregates cannot be
initialized with initializer list
'std::basic_string<_E,_Tr,_A>' : Types with private or
protected data members are not aggregate
with
[
_E=wchar_t,
_Tr=std::char_traits<wchar_t>,
_A=std::allocator<wchar_t>
]
cframe.cpp(25) : error C2552: 'cfProperties' : non-aggregates cannot be
initialized with initializer list
'std::basic_string<_E,_Tr,_A>' : Types with private or
protected data members are not aggregate
with
[
_E=wchar_t,
_Tr=std::char_traits<wchar_t>,
_A=std::allocator<wchar_t>
]
cframe.cpp(26) : error C2552: 'cfEvents' : non-aggregates cannot be
initialized with initializer list
'std::basic_string<_E,_Tr,_A>' : Types with private or
protected data members are not aggregate
with
[
_E=wchar_t,
_Tr=std::char_traits<wchar_t>,
_A=std::allocator<wchar_t>
]
cframe.cpp(26) : error C2552: 'cfEvents' : non-aggregates cannot be
initialized with initializer list
'std::basic_string<_E,_Tr,_A>' : Types with private or
protected data members are not aggregate
with
[
_E=wchar_t,
_Tr=std::char_traits<wchar_t>,
_A=std::allocator<wchar_t>
]
cframe.cpp(26) : error C2552: 'cfEvents' : non-aggregates cannot be
initialized with initializer list
'std::basic_string<_E,_Tr,_A>' : Types with private or
protected data members are not aggregate
with
[
_E=wchar_t,
_Tr=std::char_traits<wchar_t>,
_A=std::allocator<wchar_t>
]
cframe.cpp(26) : error C2552: 'cfEvents' : non-aggregates cannot be
initialized with initializer list
'std::basic_string<_E,_Tr,_A>' : Types with private or
protected data members are not aggregate
with
[
_E=wchar_t,
_Tr=std::char_traits<wchar_t>,
_A=std::allocator<wchar_t>
]



This compiler error is due to the reason:

// initialize a CLR immutable value type that has a constructor
System::DateTime dt = {2001, 4, 12, 22, 16, 49, 844}; // C2552


Question 1. How should i initialize an array of wstring?

Question 2. And what is wrong with the statement below.
wstring cfMethods[] = {{L"setLabel"},{L""}};
Respects,
Saurabh Aggrawal


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Allan W
Guest





PostPosted: Thu Dec 16, 2004 1:46 pm    Post subject: Re: wstring array? Reply with quote




Saurabh Aggrawal wrote:
Quote:
24: wstring cfMethods[] = {{L"setLabel"},{L""}};
25: wstring cfProperties[]= {{L"isVisible"},{L""}};
26: wstring cfEvents[] =
{{L"onLoad"},{L"onQueryTerminate"},{L"onTerminate"},{L""}};

The oversimplified answer is: wstring has a constructor, so you can't
use {}-style initializers. However, the array DOES use {}-style
initializers, so you have to use the outer set of {}'s!

Write this instead (but leave off the periods at the beginning of
each line, I added these to deal with Google's indent problems)

.. wstring cfMethods[] = {
.. wstring(L"setLabel"),
.. wstring(L"")
.. };
.. wstring cfProperties[]= {
.. wstring(L"isVisible"),
.. wstring(L"")
.. };
.. wstring cfEvents[] = {
.. wstring(L"onLoad"),
.. wstring(L"onQueryTerminate"),
.. wstring(L"onTerminate"),
.. wstring(L"")
.. };


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
kanze@gabi-soft.fr
Guest





PostPosted: Thu Dec 16, 2004 2:06 pm    Post subject: Re: wstring array? Reply with quote



Saurabh Aggrawal wrote:

Quote:
On line nos. 24, 25, 26

24: wstring cfMethods[] = {{L"setLabel"},{L""}};
25: wstring cfProperties[]= {{L"isVisible"},{L""}};
26: wstring cfEvents[] =
{{L"onLoad"},{L"onQueryTerminate"},{L"onTerminate"},{L""}};

i am getting the following errors:

cframe.cpp(24) : error C2552: 'cfMethods' : non-aggregates cannot be
initialized with initializer list

Why the extra braces? That's almost surely your problem. You
have a one dimensional array of a non-aggregate type.
Initializing it with something like:
{ L"message", L"" } ;
should work. When you add the extra braces, you are basically
trying to initialize a single wstring with { L"message" }. A
wstring is NOT an aggregate, and cannot be initialized with a
brace enclosed list.

--
James Kanze GABI Software http://www.gabi-soft.fr
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Ben Hutchings
Guest





PostPosted: Thu Dec 16, 2004 6:20 pm    Post subject: Re: wstring array? Reply with quote

Saurabh Aggrawal wrote:
Quote:
Hi,

On line nos. 24, 25, 26

24: wstring cfMethods[] = {{L"setLabel"},{L""}};
25: wstring cfProperties[]= {{L"isVisible"},{L""}};
26: wstring cfEvents[] =
{{L"onLoad"},{L"onQueryTerminate"},{L"onTerminate"},{L""}};

i am getting the following errors:
snip
Question 1. How should i initialize an array of wstring?

You should only use braces around the array initialisers, not around
the wstring initialisers, e.g.:

wstring cfMethods[] = {L"setLabel",L""};

Quote:
Question 2. And what is wrong with the statement below.
wstring cfMethods[] = {{L"setLabel"},{L""}};

This is interpreted as aggregate initialisation (the syntax you would
use to initialise structs in C), which is only allowed for type
without constructors.

--
Ben Hutchings
This sentence contradicts itself - no actually it doesn't.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.