i have MainWindow class, wich have the button. When the button click, it opens new form, and this form need to put in vector.
I do code like this:
Class Action controls adding form in vector and class Header is a structure of vector.I need class bcz in future i want to close all forms in vector in one moment.
#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;
};
This code crashes, when i adding vector in class Action. And output is:
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 ==========
I think, that std::vector doesnt supports smart pointers like in VS (^) please help me, how can i fix it, i need to have vector of opened forms.
^
is not a 'smart pointer', it's a .Net managed reference. It cannot be put into C++ containers, only into .Net containers.
I'd replace the vector with a System::Collections::Generic::List
.