void test(int && val)
{
val=4;
}
void main()
{
test(1);
std::cin.ignore();
}int是在调用test时创建的,还是默认情况下在c++中文字是int类型的?
发布于 2011-07-29 04:03:06
请注意,您的代码将使用C++11编译器仅编译。
当您传递整型文字时,除非您编写1L,否则将创建一个绑定到函数参数的int类型的临时对象。它类似于以下初始化中的第一个:
int && x = 1; //ok. valid in C++11 only.
int & y = 1; //error, both in C++03, and C++11
const int & z = 1; //ok, both in C++03, and C++11发布于 2011-07-29 03:53:25
调用test时,会创建一个值为1的int。文字是按其形式键入的。例如,1是整型,1.0是双精度型,"1“是字符串。
https://stackoverflow.com/questions/6864718
复制相似问题