Как мне сделать вектор / массив System :: Windows :: Forms :: Checkbox ^ - PullRequest
1 голос
/ 24 сентября 2011

Не удалось найти ответ на эту проблему или вообще не было задано ни одного вопроса. Так что я пытаюсь сделать, это std :: vector, может быть просто обычный массив флажков.

std::vector< System::Windows::Forms::CheckBox^ >m_items;
m_items.push_back( myCheckbox );

Это то, что у меня сейчас есть, и оно явно не работает. Так же у кого-нибудь есть идеи, как заставить его работать, потому что я перепробовал все, что мог, но векторы, похоже, не поддерживают флажки.

Если вам нужен код ошибки:

c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xmemory(200): error C3699: '&&' : cannot use this indirection on type 'System::Windows::Forms::CheckBox ^'
1>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector(421) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=System::Windows::Forms::CheckBox ^
1>          ]
1>          c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector(481) : see reference to class template instantiation 'std::_Vector_val<_Ty,_Alloc>' being compiled
1>          with
1>          [
1>              _Ty=System::Windows::Forms::CheckBox ^,
1>              _Alloc=std::allocator<System::Windows::Forms::CheckBox ^>
1>          ]
1>          d:\programming\vc++ projects\mahi wcs race maker\mahi wcs race maker\RestrictedItemsForm.h(69) : see reference to class template instantiation 'std::vector<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=System::Windows::Forms::CheckBox ^
1>          ]
1>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector(630): error C3699: '&&' : cannot use this indirection on type 'System::Windows::Forms::CheckBox ^'
1>c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\vector(655): error C3699: '&&' : cannot use this indirection on type 'System::Windows::Forms::CheckBox ^'
1>d:\programming\vc++ projects\mahi wcs race maker\mahi wcs race maker\RestrictedItemsForm.h(69): error C4368: cannot define 'm_items' as a member of managed 'MahiWCSRaceMaker::RestrictedItemsForm': mixed types are not supported
1>d:\programming\vc++ projects\mahi wcs race maker\mahi wcs race maker\RestrictedItemsForm.h(170): error C2663: 'std::vector<_Ty>::push_back' : 2 overloads have no legal conversion for 'this' pointer

1 Ответ

5 голосов
/ 24 сентября 2011

Обычный std::vector не поддерживает ссылочные типы CLR. Вместо этого вы должны использовать cliext::vector. Включите следующее:

#include <cliext/vector>

И использовать с:

cliext::vector<System::Windows::Forms::CheckBox^> items;
items.push_back(myCheckBox);

Конечно, вы также можете использовать обычные коллекции .Net, такие как List<T>, которые ведут себя аналогично vector.

...