Can someone explain why the following code won't compile (formatted oddly to make it a touch easier to see the problem):
ListView ^ listview = gcnew ListView();
listview->Items->AddRange( gcnew array<ListViewItem^> {
gcnew ListViewItem( gcnew array<String^> { L"red", L"fish" } ),
gcnew ListViewItem( gcnew array<String^> { L"green", L"eggs" } )
});
This gives a compile error of
error C2440: 'initializing' : cannot convert from 'const wchar_t[4]' to 'System::Windows::Forms::ListViewItem ^'
If the code is broken into two lines as follows, then all is well:
ListView^ listview = gcnew ListView();
ListViewItem^ lvi1 = gcnew ListViewItem( gcnew array<String^> { L"red", L"fish" } );
ListViewItem^ lvi2 = gcnew ListViewItem( gcnew array<String^> { L"green", L"eggs" } );
listview->Items->AddRange( gcnew array<ListViewItem^> {
lvi1,
lvi2
});
Ignoring why someone wants to make a monolithic one-liner to populate a ListView, why does the compiler have trouble instatiating the ListViewItems in the original code, and how would such a one liner be written?