In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today I will introduce to you what is the difference between the left value and the right value in C++. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.
Left value, right value definition:
The left value refers to the variable (or expression) that can appear on both the left and the right side of the equal sign, while the right value refers to the variable (or expression) that can only appear on the right side of the equal sign.
Int a + b = 3; / / illegal expression
The right value is divided into pure right value and dead value:
Pure right value: temporary variables and literal values that are not associated with objects
Dead value: when ensuring that other variables are no longer used or are about to be destroyed, by stealing, you can avoid the release and allocation of memory space and prolong the life of the variable value. The right value usually does not have a name and can only be found by reference.
Characteristics
First of all, for the base type, the right value is immutable (non-modifiable) and cannot be modified by const, volatile (cv-qualitification ignored).
Second, for a custom type (user-defined types), the right value allows you to modify it through its member functions.
Custom types should be designed to be the same as built-in types (so-called value type,value semantic), but the feature that allows member functions to change the right value intentionally or unintentionally specializes custom types.
In this regard, we can actually think of it this way: a custom type allows a member function, and calling a member function through the right value is allowed, but the member function may not be a const type, so by calling the member function of the right value, the right value may be modified.
Left value reference, right value reference
The reference type itself does not hold the memory of the bound object, but is just an alias for the object.
A left value reference is an alias for a named variable value, and a right value reference is an alias for an unnamed (anonymous) variable.
Constant left reference is a universal reference type, which can accept constant left value (with const) and initialized by non-constant left value and right value. The right value referenced by the left value of a constant can only be read-only during its lifetime
E.g.1
Int & a = 2; # left reference binds to right value, compilation fails int b = 2; # non-constant left value const int & c = b; # constant left value reference binds to non-constant left value, compiled through const int d = 2; # constant left value const int & e = c; # constant left value reference binds to constant left value, compiles through const int & b = 2 # constant left value reference binds to right value, programmatically through
E.g.2
Int a tint & & R1 = c; # failed to compile int & & R2 = std::move (a); # the above is the whole content of what is the difference between the left and right values in C++. More content related to the difference between the left and right values in C++ can be searched for previous articles or browse the following articles to learn ha! I believe the editor will add more knowledge to you. I hope you can support it!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.