Questions tagged [reference-binding]
21 questions
1
vote
1 answer
lvalue and rvalue as function parameters
I'm trying to understand Lvalue and Rvalue in C ++.
So I'm using them as parameters passed to the functions.
In this first case I have two functions, the first has a reference to an const int, in this case thanks to "const" (see link) I can pass to…

emacos
- 541
- 1
- 8
- 17
1
vote
1 answer
Why is rval ref binding to lval ref function?
In the code below, is_rvalue_reference returns true.
I would expect testRef(int &&) to be called and not testRef(int &), but that's not the case (at least with my Visual Studio 2015 compiler).
Any idea of the reason why ?
void testRef( int&& i…

MrBloom
- 91
- 6
1
vote
1 answer
invalid initialization of non-const reference of type ‘std::string&
I am trying to trim string by using function rtrim() from string header in c++ without using algorithm.
What I did was I examine start and end position by if there is space exist, simply delete it out using isspace() but when I compile, now i get…

killburn
- 83
- 2
- 8
0
votes
3 answers
Does const reference prolong the life of a temporary object returned by a temporary object?
I know that const reference prolongs the life of a temporary locally. Now I am asking myself if this propriety can be extended on a chain of temporary objects, that is, if I can safely define:
std::string const& foo =…

Alex Gidan
- 2,619
- 17
- 29
0
votes
3 answers
invalid initialization of non-const reference of type 'const char*&' from an rvalue of type 'const char *'
i made a mystrcpy function,
void mystrcpy(char *&stuff, const char *&otherstuff){
for(int i=0; stuff[i]&&other[i]; i++){
stuff[i]=other[i];
}
}
and a main function:
int main(){
char *hello="hello";
mystrcpy(hello, "bye…

hoholee12
- 334
- 3
- 14
-1
votes
1 answer
Binding const rvalues reference to non-const rvalues?
The following quotes are needed in the question:
[dcl.init.ref]/5:
5- A reference to type “cv1 T1” is initialized by an expression of
type “cv2 T2” as follows:
(5.1) [..]
(5.2) [..]
(5.3) Otherwise, if the initializer expression
(5.3.1) is an…

mada
- 1,646
- 1
- 15