引用类型方法 [英] reference type methods

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

问题描述

为什么一个方法被定义为返回一个引用,例如

运算符重载[],运算符[],


href& operator [](int index){

返回_array [index];

}


不会导致类型不匹配编译错误?


Ruben


-
http://www.mrbrklyn.com - 有趣的东西
http://www.nylxs.com - 自由软件的领导力发展


如此多的移民群体席卷布鲁克林,如亚特兰蒂斯,在世界的心灵中达到神话般的比例 - RI Safir 1998

http:/ /fairuse.nylxs.com DRM是盗窃者 - 我们是利益相关者 - RI Safir 2002


是的 - 我写自由软件...所以SUE ME


我们面临的巨大问题是我们正在成为我们自己的文化遗产的佃农 - 我们需要有能力参与我在我们自己的社会中。


我是一名工程师。我选择了最适合工作的工具,政治被诅咒。<

你必须是一个愚蠢的工程师,因为自古埃及第一王朝以来,政治和技术一直在附着。我猜你错过了那个。


??数字千年的版权

Why would a method that is defined to return a reference such as with the
operator overload of [], operator[],

href& operator[](int index){
return _array[index];
}

not cause a type mismatch compiler error?

Ruben

--
http://www.mrbrklyn.com - Interesting Stuff
http://www.nylxs.com - Leadership Development in Free Software

So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998

http://fairuse.nylxs.com DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002

"Yeah - I write Free Software...so SUE ME"

"The tremendous problem we face is that we are becoming sharecroppers to our own cultural heritage -- we need the ability to participate in our own society."

"I''m an engineer. I choose the best tool for the job, politics be damned.<
You must be a stupid engineer then, because politcs and technology have been attached at the hip since the 1st dynasty in Ancient Egypt. I guess you missed that one."

?? Copyright for the Digital Millennium

推荐答案

Ruben写道:
Ruben wrote:

为什么将一个方法定义为返回一个引用,例如

运算符重载[],运算符[],


返回_array [index];

}


不会导致类型不匹配编译错误?
Why would a method that is defined to return a reference such as with the
operator overload of [], operator[],

href& operator[](int index){
return _array[index];
}

not cause a type mismatch compiler error?



为什么要这样?假设_array是一个href数组,它只返回一个对href的

引用。


-

Ian Collins。

Why should it? Assuming _array is an array of href, it just returns a
reference to an href.

--
Ian Collins.


2008年7月14日星期一22:11:19 +1200,Ian Collins写道:
On Mon, 14 Jul 2008 22:11:19 +1200, Ian Collins wrote:

Ruben写道:
Ruben wrote:

>为什么一个方法被定义为返回一个引用,如
运算符重载[],operator [],

href& operator [](int index){
返回_array [index];
}
}
不会导致类型不匹配编译器错误?
>Why would a method that is defined to return a reference such as with
the operator overload of [], operator[],

href& operator[](int index){
return _array[index];
}
}
not cause a type mismatch compiler error?



为什么要这样?假设_array是一个href数组,它只返回一个对href的

引用。

Why should it? Assuming _array is an array of href, it just returns a
reference to an href.



hmmm


符号数组不会作为参考

它将被定义


私人:

int _array [default_size];


这来自教科书,我找到了令人费解。


Ruben

-
http://www.mrbrklyn.com - 有趣的东西
http://www.nylxs.com - 自由软件的领导力发展


如此多的移民群体席卷我们的城镇布鲁克林,如亚特兰蒂斯,达到神话世界头脑中的比例 - RI Safir 1998

http:// fairuse .nylxs.com DRM是盗窃者 - 我们是利益相关者 - RI Safir 2002


是的 - 我写自由软件...所以SUE ME


"颤抖我们面临的一个重大问题是,我们正在成为我们自己的文化遗产的佃农 - 我们需要有能力参与我们自己的社会。


我是一名工程师。我选择了最适合工作的工具,政治被诅咒。<

你必须是一个愚蠢的工程师,因为自古埃及第一王朝以来,政治和技术一直在附着。我猜你错过了那个。


??版权所有数字千年

hmmm

the symbol array would not be a reference
it would be defined

private:
int _array[default_size];

This comes up from a text book, and I found it puzzling.

Ruben
--
http://www.mrbrklyn.com - Interesting Stuff
http://www.nylxs.com - Leadership Development in Free Software

So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998

http://fairuse.nylxs.com DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002

"Yeah - I write Free Software...so SUE ME"

"The tremendous problem we face is that we are becoming sharecroppers to our own cultural heritage -- we need the ability to participate in our own society."

"I''m an engineer. I choose the best tool for the job, politics be damned.<
You must be a stupid engineer then, because politcs and technology have been attached at the hip since the 1st dynasty in Ancient Egypt. I guess you missed that one."

?? Copyright for the Digital Millennium


Ruben写道:
Ruben wrote:

2008年7月14日星期一22 :11:19 +1200,Ian Collins写道:
On Mon, 14 Jul 2008 22:11:19 +1200, Ian Collins wrote:

> Ruben写道:
>Ruben wrote:

> >为什么一个方法被定义为返回一个引用,例如用[],operator [],

href&的运算符重载。 operator [](int index){
返回_array [index];
}
}
不会导致类型不匹配编译器错误?
>>Why would a method that is defined to return a reference such as with
the operator overload of [], operator[],

href& operator[](int index){
return _array[index];
}
}
not cause a type mismatch compiler error?


为什么要这样?假设_array是一个href数组,它只返回一个对href的引用。

Why should it? Assuming _array is an array of href, it just returns a
reference to an href.



hmmm


符号数组不会作为参考

它将被定义


私人:

int _array [default_size];


hmmm

the symbol array would not be a reference
it would be defined

private:
int _array[default_size];



是的,但_array [index]在一个int。我只能猜测href是int的

typedef别名。该函数返回对该int的引用。


-

Ian Collins。

Yes, but _array[index] in an int. I can only guess that href is a
typedef alias for int. The function returns a reference to that int.

--
Ian Collins.


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

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