繁体   English   中英

在C ++中声明多个变量,是否为所有这些变量声明了属性?

[英]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);

textBtextC实际上是引用吗?
我是否必须将&放在textBtextC

谢谢!

textBtextC不是引用。 考虑&好像它属于变量而不是类型。

(只需使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM