为什么我不能在std :: vector中存储PictureBox ^?

时间:2017-10-13 19:52:51

标签: winforms vector c++-cli containers picturebox

对于我正在构建的碰撞系统,我需要有一个图像矢量:

vector<PictureBox^> Wall{ Player1,Wall_1,Wall_2 };

这是我实例化向量的方法,这不能成功编译。

vector<PictureBox^> Wall;

你可以像这样完美地实例化矢量,因为没有添加任何东西。

当我尝试使用第一个实例化编译程序时,这些是我得到的一些错误... enter image description here

我已经尝试过几乎所有符合标准的容器,例如list和deque,但是没有优势。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

您不能将标准C ++与C ++ / CLI混合使用,因为它们的类型有特殊要求(比如它们的指针是垃圾收集的)。如果要在其中存储gc-ed指针,则必须使用它们的特定容器。

例如,通用数组是List

List<PictureBox^>^ list = gcnew List<PictureBox^>();
相关问题