By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,812 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,812 IT Pros & Developers. It's quick & easy.

wstring array problem

P: n/a
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

Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Saurabh Aggrawal" <ga*****@hotmail.com> wrote in message
news:11********************@c13g2000cwb.googlegrou ps.com...
24: wstring cfMethods[] = {{L"setLabel"},{L""}};
25: wstring cfProperties[]= {{L"isVisible"},{L""}};
26: wstring cfEvents[] =
{{L"onLoad"},{L"onQueryTerminate"},{L"onTerminate" },{L""}};


The error comes from the extra {} around the parameter to
the constructor of individual wstring items -- it is not allowed.

Write the following instead:
wstring cfMethods[] = {L"setLabel",L""};

wstring cfProperties[]= {L"isVisible",L""};

wstring cfEvents[] = {L"onLoad",L"onQueryTerminate",L"onTerminate",L""} ;

hth,

Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <> http://www.brainbench.com

Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.