引用数组? [英] reference to array?
问题描述
希望你知道我的意思......
无效工作(int& r [4])
{
r [0] = 0;
}
int main(int,char **)
{
int a [4]
工作(a);
}
-
- Gernot
int main(int argc,char ** argv){printf
("%silto%c%cf%cgl%ssic%ccom%c"," ; ma,58,''g'',64," ba",46,10);}
________________________________________
寻找一个好的游戏?亲自动手吧!
GLBasic - 你可以这样做
www.GLBasic .com
Hope you know what I mean...
void Work(int& r[4])
{
r[0]=0;
}
int main(int, char**)
{
int a[4]
Work(a);
}
--
-Gernot
int main(int argc, char** argv) {printf
("%silto%c%cf%cgl%ssic%ccom%c", "ma", 58, ''g'', 64, "ba", 46, 10);}
________________________________________
Looking for a good game? Do it yourself!
GLBasic - you can do
www.GLBasic.com
推荐答案
" Gernot Frisch" < Me@Privacy.net>在消息中写道
新闻:2s ************* @ uni-berlin.de ...
"Gernot Frisch" <Me@Privacy.net> wrote in message
news:2s*************@uni-berlin.de...
希望你知道我的意思...
void工作(int& r [4])
Hope you know what I mean...
void Work(int& r[4])
void Work(int(& r)[4])
引用数组,而不是引用数组(不允许)。
john
void Work(int (&r)[4])
Reference to array, not array of references (which is not allowed).
john
Gernot Frisch写道:
Gernot Frisch wrote:
希望你知道我的意思...
void Work(int& r [4])
Hope you know what I mean...
void Work(int& r[4])
你已经声明了一个四元素的引用数组
而不是引用4个整数的数组(这将是
be int(& r)[4]。
然而,你甚至不需要它.C ++继承了来自C的
braindamaged数组传递行为一个无声的
将函数类型转换为指针到第一个元素
出现。
您的代码将起作用如果你将
函数定义为:
void工作(int r [4]){
数组不会传递值,因为它们会与其他数据一致
键入语言。数组r与调用者中的数字相同
这里。
You''ve declared a four element array of references
rather than a refernce to array of 4 ints (which would
be int (&r)[4].
However, you don''t even need that. C++ inherits the
braindamaged array passing behavior from C. A silent
conversion of the function type to pointer-to-first element
occurs.
Your code will work the way you expect if you define the
function as:
void Work(int r[4]) {
Arrays are not passed by value as would be consistant with every other
type in the language. The array r is the same as the one in the caller
here.
Gernot Frisch发布:
Gernot Frisch posted:
希望你知道我的意思......
void工作(int& r [4])
{
r [0] = 0;
}
int main(int,char **)
{
int a [4]
工作(a);
}
Hope you know what I mean...
void Work(int& r[4])
{
r[0]=0;
}
int main(int, char**)
{
int a[4]
Work(a);
}
这里有一些函数会改变4个元素的数组:
void Monkey(int * const p_blah)throw ()
{
p_blah [0] = 67;
p_blah [1] = -54;
p_blah [2] = 76;
p_blah [3] = 47;
}
void Ape(int blah [4 ])throw()//看起来它正在传递价值......
{
blah [0] = 67;
blah [1] = -54;
blah [2] = 76;
blah [3] = 47;
}
void Cow(int(& blah)[4])throw()
{
blah [0] = 67;
blah [1] = -54;
blah [2] = 76;
blah [3] = 47;
}
-JKop
Here''s some functions that''ll alter an array of 4 elements:
void Monkey(int* const p_blah) throw()
{
p_blah[0] = 67;
p_blah[1] = -54;
p_blah[2] = 76;
p_blah[3] = 47;
}
void Ape(int blah[4]) throw() //Looks like it''s passing by value...
{
blah[0] = 67;
blah[1] = -54;
blah[2] = 76;
blah[3] = 47;
}
void Cow(int (&blah)[4]) throw()
{
blah[0] = 67;
blah[1] = -54;
blah[2] = 76;
blah[3] = 47;
}
-JKop
这篇关于引用数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!