向量的向量 [英] vector of vectors

查看:78
本文介绍了向量的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经创建了一个向量向量的向量,我想把它作为一个

参数传递给一个函数。这是可能的,如果是这样,那么当我需要

指定变量类型时,函数头和函数原型的

语法是什么?

谢谢,

N.

Hi,
I''ve created a vector of vectors of ints, and I want to pass it as a
parameter to a function. Is this possible, and if so, then what is the
syntax like for the function header and function prototype when I need
to specify the variable type?
Thank you,
N.

推荐答案

" Nancy Keuss" <亩***** @ aol.com>写了...
"Nancy Keuss" <mu*****@aol.com> wrote...
我已经创建了一个int向量的向量,我想把它作为一个
参数传递给一个函数。这是可能的,如果是的话,那么当我需要
指定变量类型时,函数头和函数原型的语法是什么?
I''ve created a vector of vectors of ints, and I want to pass it as a
parameter to a function. Is this possible, and if so, then what is the
syntax like for the function header and function prototype when I need
to specify the variable type?




按价值:


void myfunction(vector< vector< int>> v);


参考:


void myotherfunction(vector< vector< int>>& vr);


通过const引用:

void mythirdfunction(vector< vector< int>> const& vc);


要定义这些函数,请用分号替换分号
函数体。不要忘记这样做''vector''是一个已知的

类型名称(包括< vector>,声明使用...)


Victor



By value:

void myfunction(vector<vector<int> > v);

By reference:

void myotherfunction(vector<vector<int> > &vr);

By a const reference:

void mythirdfunction(vector<vector<int> > const &vc);

To make a definition of those functions, replace the semicolon with
the function body. Don''t forget to make it so ''vector'' is a known
type name (include <vector>, declare using...)

Victor


" Victor Bazarov" <五******** @ comAcast.net>在消息中写道:
"Victor Bazarov" <v.********@comAcast.net> wrote in message:
" Nancy Keuss" <亩***** @ aol.com>写了...
"Nancy Keuss" <mu*****@aol.com> wrote...
我已经创建了一个向量的向量向量,我想将它作为
传递给函数。这是可能的,如果是这样,那么当$
需要指定变量类型时,什么是
的函数头和函数原型的语法?
I''ve created a vector of vectors of ints, and I want to pass it as a parameter to a function. Is this possible, and if so, then what is the syntax like for the function header and function prototype when I need to specify the variable type?



按价值:

void myfunction(vector< vector< int>> v);

参考:

void myotherfunction(vector< vector< ; int>>& vr);

由const引用:

void mythirdfunction(vector< vector< int>> const& vc);

要定义这些函数,请用函数体替换分号。不要忘记这样做''vector''是一个已知的
类型名称(包括< vector>,声明使用...)



By value:

void myfunction(vector<vector<int> > v);

By reference:

void myotherfunction(vector<vector<int> > &vr);

By a const reference:

void mythirdfunction(vector<vector<int> > const &vc);

To make a definition of those functions, replace the semicolon with
the function body. Don''t forget to make it so ''vector'' is a known
type name (include <vector>, declare using...)




你应该提到第二或第三种选择通常比第一种更好,除非你特别需要复制。

复制载体的载体可能很昂贵。


另外,''using namespace std''可能最好在函数内完成,

不在命名空间范围内。


Jonathan。



You should mention that the second or third options are generally
better than first, unless you specifically need to make a copy.
Copying vectors of vectors can be expensive.

Also, ''using namespace std'' is probably best done within functions,
not at namespace scope.

Jonathan.


" Jonathan Turkanis" < TE ****** @ kangaroologic.com>写道......
"Jonathan Turkanis" <te******@kangaroologic.com> wrote...
Victor Bazarov <五******** @ comAcast.net>在消息中写道:
"Victor Bazarov" <v.********@comAcast.net> wrote in message:
" Nancy Keuss" <亩***** @ aol.com>写了...
"Nancy Keuss" <mu*****@aol.com> wrote...
我已经创建了一个int向量的向量,我想把它作为参数传递给一个函数。这是可能的,如果是这样,那么当我需要指定变量类型时,函数头和函数原型的语法是什么?
按值:

void myfunction(vector< vector< int>> v);

参考:

void myotherfunction(vector< vector< int>>& vr);

通过const引用:

void mythirdfunction(vector< vector< int>> const& vc);

要定义这些函数,请替换分号与功能体。不要忘记这样做''vector''是一个已知的
类型名称(包括< vector>,声明使用...)
I''ve created a vector of vectors of ints, and I want to pass it as a parameter to a function. Is this possible, and if so, then what is the syntax like for the function header and function prototype when I need to specify the variable type?
By value:

void myfunction(vector<vector<int> > v);

By reference:

void myotherfunction(vector<vector<int> > &vr);

By a const reference:

void mythirdfunction(vector<vector<int> > const &vc);

To make a definition of those functions, replace the semicolon with
the function body. Don''t forget to make it so ''vector'' is a known
type name (include <vector>, declare using...)



你应该提到第二或第三个选项通常比第一个更好,除非你特别需要复制。



You should mention that the second or third options are generally
better than first, unless you specifically need to make a copy.




你应该也提到过,除非一个需要在函数中更改

向量,最好使用const引用...

复制向量向量可能很昂贵。

另外,''using namespace std''可能最好在函数内完成,而不是在命名空间范围内。



You should have also mentioned that unless one needs to change the
vector in the function, it''s better to use a const reference...
Copying vectors of vectors can be expensive.

Also, ''using namespace std'' is probably best done within functions,
not at namespace scope.




没有人建议这样做。只声明''使用''你实际上是什么

使用。


Victor



Nobody suggested that. Only declare ''using'' what you''re actually
using.

Victor


这篇关于向量的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆