[英]Declaring multiple variables in C++ , is attributes declared for all those variables?
如果我定义三个对象,如下所示:
const string & textA = messages.at(0),
textB = messages.at(1),
textC = messages.at(2);
textB
和textC
实际上是引用吗?
我是否必须将&
放在textB
和textC
?
谢谢!
textB
和textC
不是引用。 考虑&
好像它属于变量而不是类型。
(只需使用g ++进行检查)
改用此符号,您将看到会发生什么:
const string &textA = .., // reference
&textB = .., // reference
textC = ..; // value
指针同样适用:
const string *textA = .., // pointer
*textB = .., // pointer
textC = .. ;// value
综合
const string *textA = .., // pointer
&textB = .., // reference
textC = .. ;// value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.