Literal and rvalue reference

void test(int && val)
{
    val=4;
}

void main()
{  
    test(1);
    std::cin.ignore();    
}

Is it created intwhen called testor by default in C ++ inttype literals ?

+5
source share
2 answers

Please note that your code will only compile with the C ++ 11 compiler.

When you pass an integral literal, which by default is of type int, if you are not writing 1L, a temporary type object is created intthat is bound to the function parameter. This is similar to the first of the following initializations:

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
+7
source

int 1. . , 1 - int, 1.0 - double, "1" - .

0

Source: https://habr.com/ru/post/1016912/


All Articles