1
在我的解決方案中,我有C++/CLI(vs2012)項目,它在C++(vs2010)項目中執行一些方法。 下面是本機代碼簽名:如何從C++向C++/CLI返回std :: vector <std :: vector <int>>?
void Pcl::Downsample(std::vector<CloudPointNative>& points, std::vector<std::vector<int>>& clusters)
這裏是我如何執行它在C++/CLI的一面:
std::vector<std::vector<int>> clusters;
pcl->Downsample(points, clusters);
然後我嘗試遍歷集羣:
for (int clusterIndex = 0; clusterIndex < clusters.size(); clusterIndex++)
{
auto cluster = clusters[clusterIndex];
簇的大小是7,向量中的每個項目都包含int的向量。我可以在本機端的調試器中看到這一點。一旦我回到託管端(C++/cli項目),我就會遇到問題。 它工作正常,如果clusterIndex == 0和clusterIndex == 5。但拋出任何其他值clusterIndex的AccessViolationException。
auto cluster0 = clusters[0]; // works
auto cluster1 = clusters[1]; // AccessViolationException
auto cluster5 = clusters[5]; // works
這是怎麼回事?
Microsoft建議不要在DLL邊界上傳遞和返回STL類型,尤其是在不同的編譯器/版本之間。 – Medinoc
函數'Downsample'並在同一個DLL中調用它? – pogorskiy
@pogorskiy不,它們是不同的DLL。 –