c++ convert rvalue to lvalue. c++ c++11 overload-resolution rvalue Share Follow edited Jan 14, 2016 at 8:52 ildjarn 62. c++ convert rvalue to lvalue

 
c++ c++11 overload-resolution rvalue Share Follow edited Jan 14, 2016 at 8:52 ildjarn 62c++ convert rvalue to lvalue So, the conversion from a A rvalue to something that P&& would accept in (1) calls the user defined conversion function operator P() &&

str is a rvalue reference, i. Indeed it does. cv]/4. To declare an lvalue reference type, we use an ampersand (&) in the type declaration: int // a normal int type int& // an lvalue reference to an int object double& //. static_cast<Type> (expression) belongs to one of the following value categories: or an rvalue reference to a function type is an lvalue. 5 (I only have the current draft, your paragraph number may vary) we read : An lvalue for an object is necessary in order to modify the object except that an rvalue of class type can also be used to modify its referent under certain circumstances. ; In all other cases, the cast result is a (prvalue) rvalue. An lvalue does not necessarily permit modification of the object it designates. In fact, in C++11, you can go one step further and obtain a non-const pointer to an temporary: template<typename T> typename std::remove_reference<T>::type* example (T&& t) { return &t; } Note that the object the return value points to will only still exist if this function is called with an lvalue (since its argument will turn out to be. Overload resolution is usually done in terms of a strict partial. In C++03 copying the rvalue to an lvalue is the preferred choice (in some cases you can bind an lvalue reference to const to achieve a similar effect): int func2(){ // an rvalue expression. 3. オブジェクトという言葉が聞き慣れないなら. lvalue-- an expression that identifies a non-temporary object. Thus, if the thickness is 1 inch, and the K-value is 0. The pre-C++ origin of the terms "lvalue" and "rvalue" might be related to "left" and "right" side of assignment, but that meaning is only applicable in a small subset of the C++ language. –6. You would then need to add a destructor to AttrDec and delete the pointer in it and add a copy constructor. There is no lvalue-to-rvalue conversion in this scenario. ; // not legal, so no lvalue. Which basically triggers the non-const rvalue to non-const lvalue conversion and makes all the difference in the example above. Convert any type to void, evaluating and discarding the value. In the introduction to "Effective Modern C++" it says: A useful heuristic to determine whether an expression is an lvalue is to ask if you can take its address. 1Primary categories lvalue prvalue xvalue 2Mixed categories glvalue rvalue 3Special categories Pending member function call Void expressions Bit-fields Move. There's a special rule in C++ template deduction rules which says that when the parameter type is T&& where T is a deduced type, and the argument is an lvalue of type. Add a comment. I have defined two type conversion operators, one for lvalue and one for rvalue. Temporary lifetime extension does not pass through functions so there is no way to get a lvalue from the rvalue you pass to the function. Both of these options are user-defined conversion functions, so neither is better in terms of overload resolution, thus an ambiguity. This is a helper function to allow perfect forwarding of arguments taken as rvalue references to deduced types, preserving any potential move semantics involved. e. The effect of any implicit conversion is the same as performing the corresponding declaration and initialization and then using the temporary variable as the result of the conversion. 7. [ Note: If T is a non-class type that is cv. std::auto_ptr<Foo> foo(new Foo()); // auto_ptrs are deprecated btw bar(std::move(foo)); // changed ownership. However, as far as class objects are concerned. @YueZhou Function lvalues may be bound to rvalue references. The only references that are allowed to bind to object rvalues (including prvalues) are rvalue references and const non- volatile lvalue references. So a and b are converted to rvalues before getting summed. G. Of course, this is not surprising: no one would expect. And an rvalue reference is a reference that binds to an rvalue. However, it's type will be const std::string or std::string depending on the choice of const in the MyPair type. If t returns by rvalue reference, you obtain a reference to whatever was returned. has an address). If T is not a class type, the type of the rvalue (until C++11) prvalue (since C++11) is the cv-unqualified version of T. If T is a non-class type, the type of the prvalue is the cv-unqualified version of T. a non-const reference). You can disable this behaviour with the /Za (disable language extensions) compiler switch under. If T is an lvalue reference type or an rvalue reference to function type, the result is an lvalue; if T is an rvalue reference to object type, the result is an xvalue; otherwise, the result is a prvalue. Informally, "lvalue-to-rvalue conversion" means "reading the value". Both of g and h are legal and the reference binds directly. 左值(lvalue):指向内存位置的表达式被称为左值(lvalue)表达式。. In C++, the cast result belongs to one of the following value categories:. Operationally, the difference among these kinds of expressions is this:std::function can be move-constructed from rvalue of a functor object. I would like to move an object into a std::vector using std::vector::push_back(). 0. g. The compiler will synthesize a move constructor only for such class that doesn't define any of its own copy-control members (copy-constructor, copy-assignment, or destructor), and if all the non- static members. Class rvalues prvalues]. An rvalue (so-called, historically, because rvalues could appear on the right-hand side of an assignment expression) is an xvalue, a temporary object or subobject thereof, or a value that is not associated with an object. What I found by using this "real world" example is that if want to use the same code for lvalue ref and rvalue ref is because probably you can convert one to the other! std::ostringstream& operator<<(std::ostringstream&& oss, A const& a){ return operator<<(oss, a); }4. 1: (5. The example is interesting because it seems that only lvalues are combined. init. To convert an lvalue to an rvalue, you can also use the std::move() function. Hence, the end result is the attempted binding of the rvalue. All you have to do here is make sure you get a pointer to an array, rather than a pointer to the first element of the array. However, the initialization (*) of b seems weird. If you pass an prvalue, it isn't converted, the temporary is materialised into the parameter object. The goal of rvalue references is sparing copies and using move semantics. 2 1). That works well with normal variables but uint8Vect_t(dataBlock. The && syntax is either referring to a rvalue-reference or a universal-reference. A pointer is not the kind of thing that can be an rvalue or an lvalue. L-Values are locations, R-Values are storable values (i. Abbreviations of constructors, operators and destructors: Dc — Default constructorA{} is always an rvalue per [expr. const A& x = 1; //compile x = 2; //error! A&& xxx = 1; //compile A& xx = 1; //does not compile. Thus, this syntax is now legal: T&& r = T(); rvalue references primarily provide for the following: Move semantics. An lvalue (so called, historically, because lvalues could appear on the left-hand side of an assignment. e. This function takes an lvalue reference and converts it to an rvalue reference. It is still not allowed per [dcl. Per paragraph 8. e. An lvalue reference (commonly just called a reference since prior to C++11 there was only one type of reference) acts as an alias for an existing lvalue (such as a variable). And the lvalue-to-rvalue conversion always returns a prvalue value, not a (temporary) object. lvalues. However once the const keyword was added to the C++, lvalues were split into —. Rvalue reference parameters and. All lvalues that aren't arrays, functions or of. But you can take the address of an array, as with &arr. The pass-by-value version allows an lvalue argument and makes a copy of it. そう、規格書ではlvalueとrvalueとなっている。. 1 Answer. However, there is no reason why converting from one reference type to another as a cast should do anything at run time. 1. c++11标准基本上是通过举例来说明一个表达式是否是一个lvalue还是rvalue的。. Thus you need only two overloads plus recursive calls, but the exact form depends on what you. Lvalue-to-rvalue conversion C++. std::move performs a static_cast to an rvalue reference type and returns the rvalue reference. Select the Configuration Properties > C/C++ > Language property page. The first are categories for the type of a variable/member. 19, 9th bullet, three sub-bullets). If element on this position doesn't exist, it should throw exception. A lvalue overload can accept both lvalues and rvalues, but an rvalue overload can only accept rvalues. 3. It doesn't need to get the value of. It could even do so with std::move only. IBM® continues to develop and implement the features of the new standard. by unconditionally casting its argument—which might be an lvalue—to an rvalue reference, it enables the compiler to subsequently move, rather than copy, the value passed in Arg if its type is. 4/1: The result is an lvalue if T is an lvalue reference type or an rvalue reference to function type and an xvalue if T is an rvalue reference to object type; otherwise the result is a prvalue. Every expression in C and C++ is either an lvalue or an rvalue. During reference initialization, where the reference to cv1 T is bound to the lvalue or rvalue result of a conversion from the initializer expression from the class type cv2 S,. For example, if you’ve declared a variable int x;, then x is an lvalue, but 253 and x + 6 are rvalues. The following table lists exceptions to this rule. 5 Reference binding (3) and 12. Note that this must wait until construction is complete for two reasons. However, a (prvalue) rvalue cannot be converted implicitly to an lvalue or xvalue, except by user-defined conversions. @eerorika In your example y is an int, so it qualifies for rvalue conversion on return. Even if the variable's type is rvalue reference, the expression consisting of its name is an lvalue expression; now your data member m_v is vector which contains. We provide you with easy how-to’s and step-by-step instructions that provide understanding and guidance for a successful installation process, ensuring professional results. (For example std::function<void()> can be constructed. x is not assignable, because it's an rvalue in 03, a prvalue in 11 and an xvalue in 14, but using a member function always allows you to convert rvalues to lvalues (because *this is always an lvalue). Therefore, in the third line, they undergo an implicit lvalue-to-rvalue conversion. Whether it’s heap or stack, and it’s addressable. Also, xvalues do not become lvalues. The C++ language says that a local const reference prolongs the lifetime of temporary values until the end of the containing scope, but saving you the cost of a copy-construction (i. I recently filed a bug against MSVC which relates to this, where the non-standard behavior caused standard-compliant code to fail to compile and/or compile with a deviant behavior. Lvalues and xvalues can be of incomplete types, but (prvalue) rvalues must be of complete types or void types. When the template gets resolved, baz is going to be either an lvalue or an rvalue reference, depending on the call situation. But I do not see how it is related to the warning, please explain. ; T is not reference-related to U. However, if the value is const than the compiler can convert the rvalue to an lvalue duringThe title of the question you linked is a little misleading. 2. - tl:dr: Binding lvalues to rvalue-parameters is not allowed (except if the lvalue is a function), and binding rvalues to non-const lvalue-parameters is also not allowed (but const lvalue-parameters would be ok). Regarding the second question. array), and function-to-pointer (conv. Here, the developer is probably thinking - “I’ll pass in an int because it’ll get implicitly converted to an integer, and it’ll get incremented”. 9. According to the rule of forwarding reference, when an lvalue is passed to add, the template type argument Element will be deduced as SomeClass&. If encodeData() does not change dataBuff then the simplest. 1 Answer. thanks a lot! I've just another question for you. One could also say that an rvalue is any expression that is not an lvalue . 3. Therefore it makes sense that they are mutable. If you would fix the copy constructor to: DriverPoint(const DriverPoint& driverPoint) both adding lvalue and adding rvalue to the vector by calling push_back would work, but both would go through the copy ctor and not through move, as you didn't implement move and the default move is implicitly deleted if you declare any single one. That means you can't call non-const functions on the object, but if you want to pass rvalues such as temporaries, then calling non-const functions wouldn't necesarily make much sense anyway. " So an rvalue is any expression that is not an lvalue. According to the C++ specifications, it takes two rvalues as arguments and returns an rvalue. And there is no mandated lvalue-to-rvalue conversion. Firstly, pre C++17, the result of A<double>(a2) is an rvalue. Overload resolution is used to select the conversion function to be invoked. Creating a temporary object is usually not the desired behavior. It can convert lvalues to lvalue references and rvalues to rvalue references. You do pass an rvalue to some_function - but at the same time you create an argument rvalue_ref which is now an lvalue (so you can actually call the. c++ base constructor lvalue to parameter. 2) non-modifiable lvalues, which are const. Until IBM's implementation of all the features of the C++11 standard is. Every expression is either an lvalue or an rvalue, so, an rvalue is an expression that does not represent an object occupying. lval] 1. The result is an lvalue if T is an lvalue reference type or an rvalue reference to function type (8. You can also convert any. Consequently, it's not legal to apply the ++ operator to the. must error, because you're trying to pass an rvalue argument, std::move(n), to a lvalue reference parameter, T&. Otherwise, the type of the prvalue is T. ) is characterized by two independent properties: a . std::function's type is defined only by its target's signature(eg: void(int)) and std::function itself is defined by the. One more step. std::function has a non-explicit constructor that accepts lambda closures, so there is implicit conversion. Problems remaining in C++20 3. Share. For fundamental types, the copy approach is reasonable. Conversion operators are treated inconsistentlyAn lvalue can be converted to a value of an expression through lvalue conversion. 0. g. Found workaround how to use rvalue as lvalue You do not need workaround on how to use rvalue as lvalue, but rather fix your code that you do not need this workaround. — even if the implicit object parameter is not const-qualified, an rvalue can be bound to the parameter as long as in all other respects the argument can be converted to the type of the implicit object parameter. The constructed std::string rvalue is a perfect match for. 1. Let’s turn it around a bit. The second one constructs the object with an lvalue reference which reads the argument, t. 「右辺値」「左辺値」というのは 誤訳だ (正確には時代遅れ)、もう一度言うが直ちに脳内から消去するべきである。. However, you don't have double && in your code, you have U && for a deduced U. cast (this is applicable from C++11 and later). const A& x = 1; //compile x = 2; //error! A&& xxx = 1; //compile A& xx = 1; //does not compile. h and move. The term “identity” is used by the C++ standard, but is not well-defined. Yes. These get their names from the types of items that can go on the left-hand-side and right-hand-side of an assignment statement. This allows you to explicitly move from an lvalue, using move. We're talking about the temporary object created by Contrived(), it doesn't make sense to say "this object is an rvalue". In example 4, a is an lvalue, becuase it has a name and I can take its address so it's ok to bind a lvalue reference b to an lvalue (int&& a) that happens to be a rvalue reference. Don't mix the two patterns. See note at the end of this answer. Recall that there is a difference between the concept of an Lvalue and an Rvalue. Once an entity has a name, it is clearly an lvalue! If you have a name for an rvalue reference, the entity with the name is not an rvalue but an lvalue. std::forward is a conditional std::move. g. In particular, only const_cast may be used to cast away (remove) constness or volatility. I'm a bit confused about lvalue and rvalue bindings, I have the following code:. assign values to the reference return type directly in c++. But instead removing either reference overload results in ambiguity with f( int ). The only thing that can be an rvalue or an lvalue is an expression. The biggest difference between a C++03 reference (now called an lvalue reference in C++11) is that it can bind to an rvalue like a temporary without having to be const. lvalue. warning C4238: nonstandard extension used: class rvalue used as lvalue But the very same program compiles fine in gcc 11 and clang 12 with the options -std=c++20 -Wall, without any warnings. 2. (Lvalue-to-rvalue conversions on class types are rare, but do occur in some places in the language, e. 1/2: The value contained in the object indicated by the lvalue is the rvalue result. C++98 it was unspecified whether a temporary is created for an lvalue-to-rvalue conversion on the conditional operator always creates a temporary if the operator returns a class rvalue CWG 462: C++98 if the second operand of a comma operator is a temporary, it was unspecified whether its lifetime will be extended whenIt is used to convert an lvalue into an rvalue. I couldn't find an example of l2r applicable to class types myself; in all the seemingly applicable examples there's usually a function involved that takes lvalue-ref (like copy-ctor), for which l2r seems to be suppressed (see. enum type init and assignment must be enum inside,so enum type can't is lvalue。. B. The implementation of the language level is based on IBM's interpretation of the standard. 3 Viable functions (4). When C++11 invented rvalue references, none of this behavior changed at all. 2 Answers. Using rvalue references (C++11) Note: C++11 is a new version of the C++ programming language standard. And so on. 1 Lvalue-to-rvalue conversion paragraph 1 and says (emphasis mine going forward): A glvalue (3. 1 Answer. Stripping away the const using const_cast doesn't fix the issue. Something that points to a specific memory location. about undefined behaviorIf T is a reference an lvalue-reference type, the result is an lvalue; otherwise, the result is an rvalue and the lvalue-to-rvalue (conv. From a user's perspective, the meaning of it is that std::forward is a conditional cast to an rvalue. This type of static_cast is used to implement move semantics in std::move. You must explicitly use std::move (or a cast) to convert an lvalue into an rvalue reference, and an rvalue reference will never bind to an lvalue on its own. A prvalue (“pure” rvalue) is an rvalue that is not an xvalue. You are returning a copy of A from test so *c triggers the construction of a copy of c. You. int&& x = 3; x is now an lvalue. Lvalue to rvalue conversion changes the value category of an expression, without changing its type. In the previous question, I asked how this code should work: void f (const std::string &); //less efficient void f (std::string &&); //more efficient void g (const char * arg) { f (arg); } It seems that the move overload should probably be called because of the. Here’s a much more concise rundown (assuming you know basic C++ already): Every C++ expression is either an lvalue or rvalue. const foo&& can only bind to an rvalue, but const foo& can bind to both lvalues and rvalues. An lvalue can be converted to an rvalue. 3. 2, and 4. Move semantics relies on a new feature of C++11, called rvalue references, which you'll want to understand to really appreciate what's going on. Found workaround how to use rvalue as lvalue. If an lvalue or xvalue is used in a situation in which the compiler expects a (prvalue) rvalue, the compiler converts the lvalue or xvalue to a (prvalue) rvalue. The usual solution is to give the temporary a name, and then pass it like: Now, along comes C++0x - and now with rvalue references, a function defined as void foo (T&&) will allow me to. As @IgorTandetnik said - anything with a name can be assumed an lvalue. It shouldn't. One that returns an int& used when a lvalue is expected, for storing a value at a given position. When I discovered this, it seemed odd to me, so I tried. The terms "lvalue/rvalue reference" and "lvalue/rvalue" are related but not interchangeable or one a shortened form of the other. Answer below is for C++14. Does template argument resolution convert L-values to R-values or like how does this work? c++; c++11; templates;. why std::forward converts both as rvalue reference. 3 and of temporaries in 12. So. Compiled with "g++ -std=c++0x". Lvalue-to-rvalue conversion. 4. It was introduced specifically to allow temporary streams to be usable without resorting to tricks. Example: std::unique_ptr<int> get_int() { auto p = std::make_unique<int>(1); // `p` is an lvalue but treated as an rvalue in the return statement. Both of these options are user-defined conversion functions, so neither is better in terms of overload resolution, thus an ambiguity. In C++03, Boost's Foreach, using this interesting technique, can detect at run-time whether an expression is an lvalue or an rvalue. The "l" and "r" in "lvalue reference" and "rvalue reference" refers to the categories of values to which the reference can bind, not to the category of the id-expression naming a variable of this reference type. init. Jun 27 at 7:34. Therefore, if we make a reference parameter const, then it will be able to bind to any type of argument:According to the rvalue reference proposal, a named rvalue is no different from an lvalue, except for decltype. So in terms of the type analogy this means that cv T& and cv T&& are transformed to cv T if T is a class type and to T if T is a non-function non-array. I don't really understand why an rvalue and a non-modifiable lvalue would be the same. 1: A glvalue of a non-function, non-array type T can be converted to a prvalue. int array [10]; int * p = array; // [1] The expression array in [1] is an lvalue of type int (&) [10] that gets converted to an rvalue of type int *p, that is, the rvalue array of N==10 T. Types shall not be defined in a reinterpret_cast. 18. This is. The expression x is an lvalue, so it is converted. Well, neither. You could also pass it to a function accepting a const char*& (i. Put simply, an lvalue is an object reference and an rvalue is a value. If the C-value is 0. static_cast<typename remove_reference<T>::type&&> (t) The result of the function call is an rvalue (specifically, an xvalue ), so it can be bound to an rvalue reference where the function argument couldn't. if you were to use an local variable instead). In the op's example y is actually a reference to the sub-object of some unnamed object the structured binding declared. Deciding whether a function must take an argument by value, lvalue reference or rvalue reference depends very much on what it does. Suppose r is an rvalue reference or non-volatile const lvalue reference to type T, and r is to be initialized by an expression e of type U. 0) is not permitted in a core constant expression unless it meets one of three listed criteria (see C11 5. why std::forward converts both as rvalue reference. I can't speak for the motivation behind having it work this way despite the tuple explicitly holding an. lvalue = rvalue; 对于以上的语句,lvalue是我. ) In very broad and simple terms, an lvalue refers to. An obvious example of an lvalue expression is an identifier with suitable type and storage class. So, when you type const int& ref = 40. [3] Finally, this temporary variable is used as the value of the initializer. An lvalue-to-rvalue conversion is a conversion from a non-function, non-array lvalue or xvalue of type cv T to a prvalue of either type cv T if T is a class type or T if T is not a class type. void func (unsigned int& num) this function need quote type. This distinction is very important and seems to be overlooked by most when introduced to the topic. Once a move constructor is called upon the reference, the original object should be reset to the origin state, and so does any reference to it. Through an lvalue to rvalue conversion. The following diagram illustrates the relationships between the. Basically, VS will allocate the space somewhere and just let the reference point to it, as if it was a reference-to- const without the constness (or in C++11 an rvalue reference). 1. Every expression belongs to one of three value categories: lvalue, non-lvalue object (rvalue), and function designator. You can use the function template is_lvalue (below) to find out if an operand is an lvalue and use it in the function template isTernaryAssignable to find out if it can be assigned to. 14′. 21. 3. To set this compiler option in the Visual Studio development environment. h, the output is same as Clang output it's reasonable. Using lvalue references where rvalue references are required is an error: int& func2(){//compilation error: cannot bind. having an address). It's long-lived and not short-lived, and it points to a memory location where 1 is. Therefore, in the third line, they undergo an implicit lvalue-to-rvalue conversion. But i=3; is legal if i is an integer. (since C++11)20. lvalues and rvalues are expression categories, not flavours of object. Numeric literals, such as 3 and 3. If I change func (unsigned int&) to func (Color&), compiler accept it. rvalue references are marked with two ampersands (&&). This article also mentioned that issue. The entire point is that you know that this entity references an rvalue and you can legitimately move its content. 1) If the reference is an lvalue reference. C++0x, by contrast, introduces the following reference collapsing rules: The second rule is a special template argument deduction rule for function templates that take an argument by rvalue reference to a template argument: When foo is called on an lvalue of type A, then T resolves to A& and hence, by the reference collapsing rules above, the. From the linked documentation. Under the conditions specified in [dcl. Follow. As we've seen earlier, a and b are both lvalues. This allows you to explicitly move from an lvalue, using move to. But is not an lvalue that the reference can be bound to because of the wrong type. From C++11 4. The goal was providing a function that both accepts lvalue and rvalue references, I did not want to write two functions or to really care about lvalue/rvalue on the caller's side. you cannot change the integer 5, fact. 11 for the exact listing what the cast can do; what that section doesn't list, it can't do. If you really want to or need to specify the parameters, you can use std::move to convert an lvalue to an rvalue at the calling site. m, static_cast<A&&> (a), and a + a are xvalues. e. Thus, both a rvalue and another value can be assigned to values. But in this particular case, the rules. 10. 3. In this case 2*b is an rvalue since it does not persist beyond the expression. If U is t’s underlying non-reference type (namely std::remove_reference_t<decltype(t)>), then T will. Return lvalue reference from temporary object. goo<int> is an lvalue of function type, but expressions of function type are. What you're referring to is the fact that if an expression. 2. C++11 also invented the forwarding reference: that when there’s a deduced type T directly modified by &&, T can sometimes be deduced as an lvalue reference type. Properties -> C/C++ -> Language. The following table lists exceptions to this rule. I still can't figure out which one is correct though :(–In your specific case, since you are calling the function immediately you don't need to worry about taking ownership of it, so it would be better to take the function by const reference. In the previous question, I asked how this code should work: void f (const std::string &); //less efficient void f (std::string &&); //more efficient void g (const char * arg) { f (arg); } It seems that the move overload should probably be called because of the. The difference between lvalues and rvalues plays a role in the writing and understanding of expressions. 1/2 (your. Practically every example of lvalue-to-rvalue conversion I've seen on the web relates to fundamental types like int etc. Correct, the epxression T() is always an rvalue for scalar and user-defined types T. It's not needed, and suppressed. 1) Is actually not so arbitrary. Type conversions on references. 5, then the R-value is 2. If you can't, it's usually an rvalue. first) as same as the implementation of std_pair. void f2(int&& namedValue){. ; The value of i is implicitly converted to integer by constructor. 2. int a = 1, b; a + 1 = b; int *p, *q; cppreference wrote:; An xvalue is an expression that identifies an "eXpiring" object, that is, the object that may be moved from. But in the circumstances of the linked question, the template instantiation of std::function cannot be inferred from the lambda type. It can convert between pointers. lvalue simply means an object that has an identifiable location in memory (i. Confusion between rvalue references and const lvalue references as parameter. for efficient. An lvalue is an expression that designates (refers to) an object. The answer lies in the second property of expressions: the value category. M. If the target type is an inaccessible or ambiguous base of the. rvalue references are marked with two ampersands (&&). In ASCII code, the character 'a' has integer value 97 , that's why the character 'a' is automatically converted to integer 97 . 3. When you look at a parameter thing&& x its type is an rvalue reference, however, the variable named x also has a value category: it's an lvalue. X& r = X(99); // ERRORI use forward declaration here to pass object of class B as parameter in class A. lvalue and rvalue as function parameters. ASCII defines a set of characters for encoding text in computers. When you convert 99 to type X, the result is an rvalue. For example, this means, that when rvalue reference is passed to a function, an lvalue reference overload will be chosen: T&& x=T(); f(x); Links: C++ lvalue rvalue xvalue glvalue prvalue Value categories in C++ 17 Value categories. The value category of an expression (or subexpression) indicates whether an expression. Function to pointer An lvalue that is a function can be converted to a C++11 (prvalue) C++11 rvalue that is a pointer to a function of the same type, except when the expression is used as the operand of the &(address) operator, the () (function call) operator, or the sizeof operator.