Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
To get started, it's worth going over the categories of expressions in modern C++ a bit.
From the article it will be seen what 1
has the prvalue category. 1
is a literal and is not a string literal. This is a literal with a int
default type.
If you turn to the article again and look at the prvalue properties, you will see, in particular, that the prvalue:
const int& ref = 1;
or int&& ref = 1;
is completely standard. ref
in this case will refer to the passed literal and the lack of placement of the literal is not a hindrance to this. void foo( const int& ref );
void bar()
{
foo( 1 );
}
const int &ref=1;
can be found in not writing magic constants in the code. ref
- a very bad name. But naked 1
in code is even worse. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question