Comments (6)
Can you tell me where did you have problem to understand?
e.g...Do you understand the exercise 13.56?
from cpp-primer.
Hi~ @dangfeng
To fully understand what's going on here, several syntax need to grasp, which are:
1 Lvalue,Rvalue
2 Lvalue reference, Rvalue reference
3 move semantics
4 reference qualifiers for function members
5 recursion
6 this
pointer
Which part do you want to discuss in detail?
from cpp-primer.
Foo(_this).sorted()为什么会调用右值的版本呢?Foo(_this)和Foo ret(*this)有什么区别吗?
from cpp-primer.
OK. I got where you were stuck.
The statement Foo(*this).sorted();
is equivalent to (Foo(*this)).sorted();
. The expression Foo(*this)
is an Rvalue. That's why the Rvalue version sorted
will be called.
To tell Rvalue from Lvalue, you can go though other parts of CP5. Also you can use a thurm of rule like this:
Any object that can be accessed again is an Lvalue, otherwise it's an Rvalue.
Let us use this rule to compare the two expressions you listed:
Foo(*this)
This expression construct a temporary object of classFoo
, but we have no way to access that object.Therefore it's an Rvalue.
Foo ret(*this)
This expression construct a persistent object of classFoo
, we can access that object using it's variable name ret
. Therefore it's an Lvalue.
Hope it helps.
from cpp-primer.
明白了。谢谢你!
from cpp-primer.
No worries.
from cpp-primer.
Related Issues (20)
- exercise12.8 memory leakage reason?
- Got this issue
- Typo in exercise 15.34 / 15.36
- Typo in exercise 16.36
- Cpp primer answer
- Access to private member
- Cannot understand exercise 9.52, please help. HOT 1
- ex13.44 about size and length function HOT 1
- D HOT 1
- ex2.5 notation vs type? HOT 1
- Spelling error in "Exercise 4.7" HOT 1
- Spelling error in Exercise 4.14 HOT 1
- Spelling error in Exercise 4.28 HOT 1
- "Include" error in ex15.4.5.6
- Cpp
- Ch 16 - some further reading for ex65 and 66
- A issue made by mistake.
- Ex 14.28 problem
- Ex13.42 HOT 1
- Exercise 10_32.cc (G++ giving error on the accumulate algorithm)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpp-primer.