【问题标题】:How do I make a vector/array of System::Windows::Forms::Checkbox^如何制作 System::Windows::Forms::Checkbox^ 的向量/数组
【发布时间】:2011-11-24 04:00:34
【问题描述】:

找不到此问题的任何答案,甚至没有提出任何问题。 所以我想要做的是一个 std::vector,也许只是一个普通的 Checkbox 数组。

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

【问题讨论】:

    标签: windows arrays vector checkbox c++-cli


    【解决方案1】:

    常规 std::vector 不支持 CLR 引用类型。相反,您必须使用cliext::vector。包括以下内容:

    #include <cliext/vector>
    

    并用于:

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

    当然,您也可以使用常规的 .Net 集合,例如 List&lt;T&gt;,其行为类似于 vector

    【讨论】:

    • @HansPassant:不包含完整项目的基准测试没有太大帮助。甚至没有提及使用了哪些编译器选项的基准比无用更糟糕。
    • 嗯,我很了解 Nish。好人,我知道他做得对。无论如何,很明显,STL/CLR 结合了 STL(值类型行为)的最差特性和 .NET(引用类型行为)的最差特性。以三年为线索。没有人使用它。没有人应该使用它。没有人这样做。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 1970-01-01
    • 2012-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多