I have a large C++ API, which I need to wrap in a C++/CLI skin to make available in .NET
For the most part it works fine, but I have encountered one area that causes a polymorphism problem.
On the pure C++ API I have a function like:
vector<Parent*> getCppObjects()
{
return myVector;
}
Parent is a type with two children ChildA and ChildB. On the CLI side I will have a function:
List<CLIParent^> getCliObjects()
{
List<CLIParent^> myList = gcnew List<CLIParent^>();
vector<Parent*> myVector = getCppObjects();
for int i=0; i < myVector.size(); ++i)
{
myList->add(gcnew CLIParent(myVector->at(i)));
}
return myList;
}
CLI Parent has constructor that accepts type Parent, and there are similar classes for the child types. My problem is that at the C++ layer I can cast objects to their correct type, but because of the way I have wrapped them at the CLI layer (as always being of the parent type) I cannot use them as CLI versions of the child types.
Do I need to use something like typeid and a switch/factory to create the appropriate types in my CLI API or is there a more elegant solution?