G
Guest
Hello,
I'm using Managed C++ in .NET 2003. I'm trying to map integers to Enums
inside an STL map container, but I cannot get it to compile. This might be a
simple question, and I'm sure I'm missing something, but I haven't used STL a
lot inside MC++. Here's my code:
#include <map>
#include <vcclr.h>
public __gc class Managed
{
public:
__value enum MyEnum
{
Value1,
Value2,
Value3
};
typedef std::map<int, gcroot<MyEnum*> > MyMap;
static MyMap* _myMap = new MyMap();
Managed()
{
_myMap->insert(MyMap::value_type(123, __box(MyEnum::Value1)));
}
};
int _tmain()
{
return 0;
}
The compiler errors I'm getting are as follows:
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\gcroot.h(61)
: error C2665: 'System::Runtime::InteropServices::GCHandle::Alloc' : none of
the 2 overloads can convert parameter 1 from type 'Managed::MyEnum __gc *'
StlMapWithMgdEnum.cpp(0): could be
'System::Runtime::InteropServices::GCHandle
System::Runtime::InteropServices::GCHandle::Alloc(System::Object __gc *)'
while trying to match the argument list '(Managed::MyEnum __gc *)'
C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\gcroot.h(60) : while compiling class-template member
function 'gcroot<T>::gcroot(Managed::MyEnum __gc *)'
with
[
T=Managed::MyEnum __gc *
]
C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\utility(51) : see reference to class template instantiation
'gcroot<T>' being compiled
with
[
T=Managed::MyEnum __gc *
]
StlMapWithMgdEnum.cpp(19) : see reference to class template
instantiation 'std:air<_Ty1,_Ty2>' being compiled
with
[
_Ty1=const int,
_Ty2=gcroot<Managed::MyEnum __gc *>
]
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\gcroot.h(63)
: error C2228: left of '.ToInt32' must have class/struct/union type
Is it possible to do what I'm attempting here? I want to use std::map for
the type safety, but do I need to punt and resort to using a
System::Collections::Hashtable and __box everything?
Thanks!
I'm using Managed C++ in .NET 2003. I'm trying to map integers to Enums
inside an STL map container, but I cannot get it to compile. This might be a
simple question, and I'm sure I'm missing something, but I haven't used STL a
lot inside MC++. Here's my code:
#include <map>
#include <vcclr.h>
public __gc class Managed
{
public:
__value enum MyEnum
{
Value1,
Value2,
Value3
};
typedef std::map<int, gcroot<MyEnum*> > MyMap;
static MyMap* _myMap = new MyMap();
Managed()
{
_myMap->insert(MyMap::value_type(123, __box(MyEnum::Value1)));
}
};
int _tmain()
{
return 0;
}
The compiler errors I'm getting are as follows:
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\gcroot.h(61)
: error C2665: 'System::Runtime::InteropServices::GCHandle::Alloc' : none of
the 2 overloads can convert parameter 1 from type 'Managed::MyEnum __gc *'
StlMapWithMgdEnum.cpp(0): could be
'System::Runtime::InteropServices::GCHandle
System::Runtime::InteropServices::GCHandle::Alloc(System::Object __gc *)'
while trying to match the argument list '(Managed::MyEnum __gc *)'
C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\gcroot.h(60) : while compiling class-template member
function 'gcroot<T>::gcroot(Managed::MyEnum __gc *)'
with
[
T=Managed::MyEnum __gc *
]
C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\utility(51) : see reference to class template instantiation
'gcroot<T>' being compiled
with
[
T=Managed::MyEnum __gc *
]
StlMapWithMgdEnum.cpp(19) : see reference to class template
instantiation 'std:air<_Ty1,_Ty2>' being compiled
with
[
_Ty1=const int,
_Ty2=gcroot<Managed::MyEnum __gc *>
]
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\gcroot.h(63)
: error C2228: left of '.ToInt32' must have class/struct/union type
Is it possible to do what I'm attempting here? I want to use std::map for
the type safety, but do I need to punt and resort to using a
System::Collections::Hashtable and __box everything?
Thanks!