I have a C# front end and a C++ backend for performance reasons. Now I would like to call a C++ function like for example:
void findNeighbors(Point p, std::v
The impedance mismatch is severe. You have to write a wrapper in the C++/CLI language so that you can construct a vector. An additional problem is Point, your C++ declaration for it is not compatible with the managed version of it. Your code ought to resemble this, add it to a class library project from the CLR node.
#include
using namespace System;
using namespace System::Collections::Generic;
struct Point { int x; int y; };
void findNeighbors(Point p, std::vector &neighbors, double maxDist);
namespace Mumble {
public ref class Wrapper
{
public:
List^ FindNeigbors(System::Drawing::Point p, double maxDist) {
std::vector neighbors;
Point point; point.x = p.X; point.y = p.Y;
findNeighbors(point, neighbors, maxDist);
List^ retval = gcnew List();
for (std::vector::iterator it = neighbors.begin(); it != neighbors.end(); ++it) {
retval->Add(System::Drawing::Point(it->x, it->y));
}
return retval;
}
};
}
Do note the cost of copying the collection, this can quickly erase the perf advantage you might get out of writing the algorithm in native C++.