简体   繁体   English

C#数组到C ++向量

[英]C# arrays to C++ vectors

What is the equivalent from C# to C++ of doing this: 从C#到C ++的等效功能是什么:

int[n][num] card;
someFunction(card[0]);


someFunction(int[] card)
{
    ....
}

Using vectors in C++ 在C ++中使用向量


Also

Is this code in C++: 这是C ++中的代码吗?

std::vector< std::vector <int> > a(numA, vector<int>());

equivalent to this code in C# ?: 等效于C#中的以下代码?

int[][] a = new int[numA][];

If it is not, please tell me how it should be. 如果不是,请告诉我应该如何。 Thanks. 谢谢。

I don't know C# but this looks right 我不知道C#,但是看起来不错

std::vector< std::vector<int> > card;
someFunction(card[0]);


void someFunction(const std::vector<int>& card)
{
    ....
}

Use & to indicate that you are passing the vector by reference to avoid the overhead of copying the vector itself. 使用&表示您正在通过引用传递向量,以避免复制向量本身的开销。 If you want someFunction to modify the vector then drop the const . 如果要让someFunction修改向量,则删除const

Your other code looks OK too. 您的其他代码也可以。

vector<vector<int> > card(n, std::vector<int>(num));
someFunction(card[0]);

someFunction(vector<int> vec)
{
    ....
}

This: 这个:

std::vector< std::vector <int> > a(numA, vector<int>());

and simpler 更简单

std::vector< std::vector <int> > a(numA);

are C++ jagged arrays equivalent to: 是C ++锯齿状数组,等效于:

int[][] a = new int[numA][];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM