How do I make a vector/array of System::Windows::Forms::Checkbox^

人走茶凉 提交于 2020-01-03 02:41:06

问题


Couldn't find any answer to this problem, or not even any questions asked. So what I'm trying to do, is a std::vector, maybe just a normal array, of Checkboxes.

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

That's what I currently have, and it clearly ain't working. So does anyone have any ideas, on how to get it working, cause I've tried everything I can, but vectors don't seem to support Checkboxes.

Incase you need the error code:

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:


The regular std::vector does not support CLR reference types. Instead, you must use cliext::vector. Include the following:

#include <cliext/vector>

And use with:

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

Of course, you can also use the regular .Net collections, like List<T>, which behaves similarly as a vector.



来源:https://stackoverflow.com/questions/7537809/how-do-i-make-a-vector-array-of-systemwindowsformscheckbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!