在非託管C++中我有一個函數,我試圖從C#調用。這個C++函數如下:如何使用std :: vector <> :: iterator作爲參數從C#調用非託管C++函數?
typedef std::vector<Point> Points;
typedef std::back_insert_iterator<Points> OutputIterator;
namespace MYNAMESPACE{
DLLEXPORT OutputIterator convexHull(Points::iterator first, Points::iterator last, OutputIterator result);
}
在C++中調用,該函數用於如下:
Points points, result;
points.push_back(Point(0,0));
points.push_back(Point(10,0));
points.push_back(Point(10,10));
points.push_back(Point(6,5));
points.push_back(Point(4,1));
OutputIterator resultIterator = std::back_inserter(result);
MYNAMESPACE::convexHull(points.begin(), points.end(), resultIterator);
std::cout << result.size() << " points on the convex hull" << std::endl;
我已經開始寫C#代碼,但我不知道是什麼類型我要傳遞:在C#
[DllImport("unmanagedCode.dll", EntryPoint = "convexHull", CallingConvention = CallingConvention.StdCall)]
public static extern ???<Point> convex_hull_2(???<Point> start, ???<Point> last, ???<Point> result);
Point結構就是:
struct Point{
double x;
double y;
}
是傳遞數組還是點列表的情況?
我有源代碼到C++並可以對函數參數進行更改;會不會有更容易從C#調用的不同類型的參數?