Hi, dear all,
I want to wrapper the legacy C++ Template Class to be used by the C#
code, so I try to wrapper the legacy C++ code into CLI/C++ code first.
One problem is how to wrapper C++ template class, such as List, Queue,
etc?
Here is a snippet of Native Code:
//Native code:
namespace Unmgd
{
template <class Tclass ArrayList
{
private:
T* mArray;
Int mLength;
public:
T Get(int index)
{
return mArray[index];
}
void Set(int index, T value)
{
mArray[index] = value;
}
};
class ListofInts : public ArrayList<int {};
class ListofFloats: public ArrayList<float{};
class ListofShorts: public ArrayList<short{};
}
So, what's the best way to do the wrapper of these classes, such as
ListofInts , ListofFloats?
My wrapper code is:
//Wrapper code:
namespace Mgd
{
template <class T1, class T2public ref class ArrayList
{
public:
property T1 default[int]
{
T1 get(int index)
{
return (*Native())[index];
}
void set(int index, T1 value)
{
(*Native())[index] = value;
}
}
internal:
virtual T2* Native() = 0;
};
public ListofInts : public ArrayList<int, Unmgd::ListofInts>
{
private:
//mpNative is the pointer to the native instance.
Unmgd::ListofInts* mpNative;
internal:
virtual Unmgd::ListofInts* Native() override
{
return mpNative;
}
};
}