为了尝试在托管的.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