首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用std::具有智能指针的向量

使用std::具有智能指针的向量
EN

Stack Overflow用户
提问于 2015-04-12 16:34:53
回答 1查看 180关注 0票数 1

我有MainWindow课程,还有按钮。当按钮单击时,它将打开新窗体,此表单需要放入向量。

我做这样的代码:

类操作控件在向量中添加表单,类头是向量的结构,将来需要类bcz,我想在一分钟内关闭向量中的所有表单。

代码语言:javascript
复制
#pragma once
#include "MyForm.h"
#include <vector>

using namespace std;

ref class Header
{
    public:
    Client::MyForm ^x;
    void Close(){ x->Close();}
};

class Action
{
public:
    vector<Header> vec;
};

当我在“类操作”中添加向量时,这段代码会崩溃。产出如下:

代码语言:javascript
复制
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(516): error C3699: '*' : cannot use this indirection on type 'Header'
1>          compiler replacing '*' with '^' to continue parsing
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\type_traits(572) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=Header
1>          ]
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(650) : see reference to class template instantiation 'std::is_empty<_Alloc>' being compiled
1>          with
1>          [
1>              _Alloc=std::allocator<Header>
1>          ]
1>          c:\users\user\desktop\client\client\Header.h(17) : see reference to class template instantiation 'std::vector<Header,std::allocator<_Ty>>' being compiled
1>          with
1>          [
1>              _Ty=Header
1>          ]
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(517): error C3699: '*' : cannot use this indirection on type 'const Header'
1>          compiler replacing '*' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(521): error C3699: '&' : cannot use this indirection on type 'Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(522): error C3699: '&' : cannot use this indirection on type 'const Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(586): error C3699: '*' : cannot use this indirection on type 'Header'
1>          compiler replacing '*' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(591): error C3699: '*' : cannot use this indirection on type 'Header'
1>          compiler replacing '*' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(591): error C3699: '&' : cannot use this indirection on type 'const Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(683): error C3699: '*' : cannot use this indirection on type 'Header'
1>          compiler replacing '*' with '^' to continue parsing
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(755) : see reference to class template instantiation 'std::allocator_traits<_Alloc>' being compiled
1>          with
1>          [
1>              _Alloc=std::allocator<Header>
1>          ]
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(443) : see reference to class template instantiation 'std::_Wrap_alloc<std::allocator<_Ty>>' being compiled
1>          with
1>          [
1>              _Ty=Header
1>          ]
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(579) : see reference to class template instantiation 'std::_Vec_base_types<_Ty,_Alloc>' being compiled
1>          with
1>          [
1>              _Ty=Header
1>  ,            _Alloc=std::allocator<Header>
1>          ]
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(652) : see reference to class template instantiation 'std::_Vector_alloc<false,std::_Vec_base_types<_Ty,_Alloc>>' being compiled
1>          with
1>          [
1>              _Ty=Header
1>  ,            _Alloc=std::allocator<Header>
1>          ]
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(684): error C3699: '*' : cannot use this indirection on type 'const Header'
1>          compiler replacing '*' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(763): error C3699: '&' : cannot use this indirection on type 'Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(765): error C3699: '&' : cannot use this indirection on type 'const Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(861): error C3699: '*' : cannot use this indirection on type 'Header'
1>          compiler replacing '*' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(105): error C3699: '*' : cannot use this indirection on type 'Header'
1>          compiler replacing '*' with '^' to continue parsing
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(449) : see reference to class template instantiation 'std::_Is_simple_alloc<std::_Wrap_alloc<std::allocator<_Ty>>>' being compiled
1>          with
1>          [
1>              _Ty=Header
1>          ]
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(107): error C3699: '*' : cannot use this indirection on type 'const Header'
1>          compiler replacing '*' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(109): error C3699: '&' : cannot use this indirection on type 'Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(111): error C3699: '&' : cannot use this indirection on type 'const Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(122): error C3699: '*' : cannot use this indirection on type 'Header'
1>          compiler replacing '*' with '^' to continue parsing
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(469) : see reference to class template instantiation 'std::_Simple_types<Header>' being compiled
1>          C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(580) : see reference to class template instantiation 'std::_Vector_val<std::_Simple_types<Header>>' being compiled
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(123): error C3699: '*' : cannot use this indirection on type 'const Header'
1>          compiler replacing '*' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(124): error C3699: '&' : cannot use this indirection on type 'Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(125): error C3699: '&' : cannot use this indirection on type 'const Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(487): error C3265: cannot declare a managed '_Myfirst' in an unmanaged 'std::_Vector_val<std::_Simple_types<Header>>'
1>          may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(488): error C3265: cannot declare a managed '_Mylast' in an unmanaged 'std::_Vector_val<std::_Simple_types<Header>>'
1>          may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(489): error C3265: cannot declare a managed '_Myend' in an unmanaged 'std::_Vector_val<std::_Simple_types<Header>>'
1>          may not declare a global or static variable, or a member of a native type that refers to objects in the gc heap
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(704): error C3699: '&' : cannot use this indirection on type 'const Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(710): error C3699: '&' : cannot use this indirection on type 'const Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(797): error C3699: '*' : cannot use this indirection on type 'const Header'
1>          compiler replacing '*' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(864): error C3699: '&&' : cannot use this indirection on type 'Header'
1>          compiler replacing '&&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(887): error C3699: '&&' : cannot use this indirection on type 'Header'
1>          compiler replacing '&&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(1118): error C3699: '&' : cannot use this indirection on type 'const Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(1242): error C3699: '&' : cannot use this indirection on type 'const Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(1320): error C3699: '&' : cannot use this indirection on type 'const Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(1326): error C3699: '&' : cannot use this indirection on type 'const Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(1332): error C3699: '&' : cannot use this indirection on type 'const Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(1581): error C3699: '*' : cannot use this indirection on type 'const Header'
1>          compiler replacing '*' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(1652): error C3699: '&' : cannot use this indirection on type 'const Header'
1>          compiler replacing '&' with '^' to continue parsing
1>C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\vector(1745): error C3699: '*' : cannot use this indirection on type 'const Header'
1>          compiler replacing '*' with '^' to continue parsing
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我想,std::vector不支持VS (^)这样的智能指针--请帮帮我,我该如何修复它,我需要打开表单的向量。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-12 16:39:27

^不是一个“智能指针”,它是一个.Net托管引用。它不能放到C++容器中,只能放进.Net容器中。

我会用一个System::Collections::Generic::List来代替向量。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29591786

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档