I was trying to figure out this exercise from a school exam. They implemented an abstract template Book class, and the assignment is to implement a bo ...
I was trying to figure out this exercise from a school exam. They implemented an abstract template Book class, and the assignment is to implement a bo ...
Consider this code: void test(auto& arg){} int main(){ test("bla"); test(1); } The call test(1); gives an error, because 1 is an rvalu ...
Why is data in func() repeated? ...
I have an interesting example to understand lvalue reference, rvalue reference, and std::forward. Maybe it will be a useful example for a deep underst ...
I have declared a two dimensional character array matrix[][]. In a function vacantCenter(), I am trying to return 1, if matrix[1][1] stores a white ...
I've just read this in C++ Primer : A function parameter that is an rvalue reference to a template type parameter (i.e., T&&) preserves th ...
There are countless explanations as to what the differences between glvalues and prvalues are, but they all pretty much boil down to "everything that ...
I have a function that returns a lowercase string: and I expect that function return the same resultat when i will pass "SOME" or const std::string ...
I am new to c++. For this code is_lvalue(fun()) return true. And This I understand, as lvalue reference are afterall lvalues. But for code, is_l ...
Hello I am a beginner learner in c , today I saw some tricky usage example code in cppreference.com struct tm tm = *localtime(&(time_t){time(NULL ...
Consider this code: There is a friend function in line 14. this function declares an object inside its body. and at the the end returns that object ...
I know it's a bad attempt but why we cannot edit the private member via the getter? I think GetA1() doesn't work because it's using a rvalue, the c ...
I was studying about l-values and r-values but I am confused with this: I know about int a = get_val(); (i.e., it will assign the returned value to ...
Having this: output: expecting: I would expect that since the A::save returns a reference to the last element of the vector, the changes made ...
I have a function f that takes a string as input. I usually want to provide a string literal, e.g., f("hello"). However, I want to implement another f ...
Consider the following C code: ++ has precedence over += so it should be evaluated first. So we have a on the left and 1 on the right. Now based on ...
I am probably missing something basic here, but why don't I get a lvalue from std:forward bellow? this compiles to I would expect the last resul ...
I am a newbie with this topic in cpp and trying to usnderstand through this code, so please tell me how l-values and r-values make difference in this ...
The commented line in the following snippet does not work as expected: Specifically, I would like to return both an rvalue and an lvalue in a singl ...
When using the scanf function, we cannot simply specify the variable name. Rather, we have to prefix the variable name with an ampersand, e.g. int a; ...