我不明白以下返回类型的区别以及其中一些甚至如何编译?
const bool && const Method1(){
.....
}
这个的返回是什么?常量(rval)引用常量值?
const bool const Method1(){
.....
}
Constant bool 常量(我不明白如果我返回一个值,这里怎么会有两个常量)
const bool & const Method1(){
.....
}
也不知道,常量引用常量值?
哪个最适合用于只读返回值?
最佳答案
const bool const Method1();
不编译。const bool&& Method1();
它编译。关于它的实用性 here一些引用资料。const bool & const Method1();
不编译。
更新
Visual Studio 它给了我
main.cpp(5): warning C4114: same type qualifier used more than once
main.cpp(6): warning C4227: anachronism used: qualifiers on reference are ignored
这只是说 Visual Studio 会忽略该限定符(形式 (1)、(3))。
关于c++ - 有人可以解释这些函数返回类型的区别吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39562695/