wstring array problem

S

Saurabh Aggrawal

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
 
I

Ivan Vecerina

Saurabh Aggrawal said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,206
Latest member
SybilSchil

Latest Threads

Top