代码:
#include <iostream>
int main() {
int a = 137;
const int &b = a;
std::cout << a << " " << b << std::endl; // prints 137 137
a++;
std::cout << a << " " << b << std::endl; // prints 138 138
}
Run Code Online (Sandbox Code Playgroud)
变量的值在语句之后b变为,尽管它被声明为Shouldn't this be not allowed? 如何确保这不会发生?或者至少会因此而受到警告。138a++const
我在用GNU GCC Compiler
c++ ×1