爲了嘗試在託管的.dll中包裝一些非託管代碼,我試圖將數據點的Generic::List
轉換爲std::vector
。下面是我想要做的一個片段:如何通過引用傳遞Generic :: List?
namespace ManagedDLL
{
public ref class CppClass
{
void ListToStdVec(const List<double>& input_list, std::vector<double>& output_vector)
{
// Copy the contents of the input list into the vector
// ...
}
void ProcessData(List<double> sampleData)
{
std::vector<double> myVec;
ListToStdVec(sampleData, myVec);
// Now call the unmanaged code with the new vector
// ...
}
}
}
編譯這給了我:
錯誤C3699:「&」:對類型不能用這種間接「常量系統::類別: :通用::名單」
我可能錯過這裏一些基本的東西(我是比較新的做事.NET的方式),但看起來合理合法的代碼給我..?
[編輯]我已經試過了安迪和達里奧的建議,他們的工作,但我該如何訪問輸入列表的成員?我已經試過各種dreferencing並沒有什麼的組合看起來編譯:
void ListToStdVec(const List<double>% input_list, std::vector<double>& output_vector)
{
int num_of_elements = input_list->Count;
}
void ListToStdVec(const List<double>^ input_list, std::vector<double>& output_vector)
{
int num_of_elements = input_list.Count;
}
...既給我:
錯誤C2662:「系統::收藏集::一般::名單:: Count :: get':無法將'this'指針從'const System :: Collections :: Generic :: List'轉換爲'System :: Collections :: Generic :: List%'
.. .so如何訪問參考/指針?
刪除const確實允許我訪問input_list的成員,但我喜歡在任何可能的情況下使輸入爲const,因爲它經常在編譯時捕獲錯誤。 – 2009-05-20 09:21:32