参考参考 [英] Reference to a reference
问题描述
我正在阅读现代C ++设计,其中Anderi引用了C ++不允许
引用引用。
假设我有
DoThat(const string& strData2)
{
...
}
DoThis(const string& strData)
{
..
DoThat(strData) ;
}
int main()
{
字符串数据;
DoThis(数据);
}
现在我在DoThis里面的strData是对Data的引用。
strData2我有一个对strData.ie的引用strData2是一个参考
参考。
这里安德烈的声明让我感到困惑......我失去了什么?
谢谢,
Senthil
Hi,
I am reading Modern C++ Design where Anderi quoted "C++ does not allow
references to references".
Assume i have
DoThat(const string& strData2)
{
...
}
DoThis(const string& strData)
{
..
DoThat(strData);
}
int main()
{
string Data;
DoThis(Data);
}
Now the strData i have inside DoThis is a reference to Data.The
strData2 I have is a reference to strData.i.e strData2 is a reference
to a reference.
Here Andrei''s statement confuses me..Am i missing something?
Thanks,
Senthil
推荐答案
Senthil写道:
Senthil wrote:
我正在阅读现代C ++设计,其中Anderi引用C ++不允许
参考参考文献。
假设我有这个问题(const string& strData2)
{
...
DoThis(const string& strData)
{
..
DoThat (strData);
}
int main()
{
字符串数据;
DoThis(数据);
}
现在strData我在里面DoThis是对Data的引用。
strData2我有一个strData.ie引用strData2是一个参考
来引用。
这里安德烈的陈述使我感到困惑......我错过了什么?
谢谢,
Senthil
Hi,
I am reading Modern C++ Design where Anderi quoted "C++ does not allow
references to references".
Assume i have
DoThat(const string& strData2)
{
...
}
DoThis(const string& strData)
{
..
DoThat(strData);
}
int main()
{
string Data;
DoThis(Data);
}
Now the strData i have inside DoThis is a reference to Data.The
strData2 I have is a reference to strData.i.e strData2 is a reference
to a reference.
Here Andrei''s statement confuses me..Am i missing something?
Thanks,
Senthil
什么是上下文(部分编号和段落)?也许他的意思是
你不能用引用用指针做什么:
int anInt = 42;
int * pointer_to_int =& anInt;
int ** pointer_to_pointer_to_int =& pointer_to_int;
干杯! --M
What''s the context (section number and paragraph)? Perhaps he means
that you can''t do with references what you can do with pointers:
int anInt = 42;
int *pointer_to_int = &anInt;
int **pointer_to_pointer_to_int = &pointer_to_int;
Cheers! --M
Senthil写道:
Senthil wrote:
我正在读书现代C ++设计,其中Anderi引用了C ++不允许引用引用。
假设我有#That(const string& strData2)
{
...
}
DoThis(const string& strData)
{
..
DoThat(strData);
}
int main()
{
字符串数据;
DoThis(数据);
}
现在strData i有里面的DoThis是对Data的引用。
strData2我有一个对strData.ie strData2的引用是一个引用的参考。
这里你错了。 strData2是一个字符串的引用,根据
它的声明。
这里安德烈的声明让我很困惑......我错过了什么?
>谢谢,
Senthil
Hi,
I am reading Modern C++ Design where Anderi quoted "C++ does not allow
references to references".
Assume i have
DoThat(const string& strData2)
{
...
}
DoThis(const string& strData)
{
..
DoThat(strData);
}
int main()
{
string Data;
DoThis(Data);
}
Now the strData i have inside DoThis is a reference to Data.The
strData2 I have is a reference to strData.i.e strData2 is a reference
to a reference. Here you are wrong. strData2 is a reference to a string according with
its declaration.
Here Andrei''s statement confuses me..Am i missing something?
Thanks,
Senthil
/ dan
/dan
Senthil写道:
Senthil wrote:
我正在阅读现代C ++设计,其中Anderi引用了C ++不允许引用引用。
假设我有
DoThat(const string& strData2)
根据声明,strData2是对const字符串的引用。
{
...
DoThis(const string& strData)
根据声明,strData是对const string的引用。 />
{
..
DoThat(strData);
}
int main()
{
字符串数据;
DoThis(数据);
}
现在我在DoThis里面的strData是对Data的引用。
strData2我有一个strData的引用。
这是对数据的引用。
即strData2是对引用的引用。
Hi,
I am reading Modern C++ Design where Anderi quoted "C++ does not allow
references to references".
Assume i have
DoThat(const string& strData2)
According to the declaration, strData2 is a reference to const string.
{
...
}
DoThis(const string& strData)
According to the declaration, strData is a reference to const string.
{
..
DoThat(strData);
}
int main()
{
string Data;
DoThis(Data);
}
Now the strData i have inside DoThis is a reference to Data.The
strData2 I have is a reference to strData.
It''s a refernce to Data.
i.e strData2 is a reference to a reference.
编号如果允许,对参考文献的引用将被声明为:
const string&& strData2
No. If allowed, a reference to a reference would be declared something like:
const string&& strData2
这篇关于参考参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!