Giter Club home page Giter Club logo

Comments (6)

Mooophy avatar Mooophy commented on June 18, 2024

Can you tell me where did you have problem to understand?
e.g...Do you understand the exercise 13.56?

from cpp-primer.

Mooophy avatar Mooophy commented on June 18, 2024

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.

dangfeng avatar dangfeng commented on June 18, 2024

Foo(_this).sorted()为什么会调用右值的版本呢?Foo(_this)和Foo ret(*this)有什么区别吗?

from cpp-primer.

Mooophy avatar Mooophy commented on June 18, 2024

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.

dangfeng avatar dangfeng commented on June 18, 2024

明白了。谢谢你!

from cpp-primer.

Mooophy avatar Mooophy commented on June 18, 2024

No worries.

from cpp-primer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.