Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6984665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:34:43+00:00 2026-05-27T18:34:43+00:00

In C++11, methods can be overloaded on whether or not the expression that denotes

  • 0

In C++11, methods can be overloaded on whether or not the expression that denotes the object on which the method is called is an lvalue or an rvalue. If I return *this from a method called via an rvalue, do I need to explicitly move from *this or not?

Foo Foo::method() &&
{
    return std::move(*this);   // Is this move required or not?
}

Unfortunately, I can’t simply test this on my compiler since g++ does not support this feature yet 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:34:43+00:00Added an answer on May 27, 2026 at 6:34 pm

    The type of *this is always an lvalue:

    §9.3.2 [class.this] p1

    In the body of a non-static (9.3) member function, the keyword this is a prvalue expression whose value is the address of the object for which the function is called. The type of this in a member function of a class X is X*. […]

    §5.3.1 [expr.unary.op] p1

    The unary * operator performs indirection: the expression to which it is applied shall be a pointer to an object type, or a pointer to a function type and the result is an lvalue referring to the object or function to which the expression points.

    So you will need to std::move if you want to invoke the move constructor.

    The following code snippet shows that:

    #include <iostream>
    #include <utility>
    
    struct test{
      test(){}
      test(test const&){ std::cout << "copy ctor // #1\n"; }
      test(test&&){ std::cout << "move ctor // #2\n"; }
    
      test f_no_move() &&{ return *this; }
      test f_move() &&{ return std::move(*this); }
    };
    
    int main(){
      test().f_no_move(); // #1
      test().f_move(); // #2
    }
    

    Using Clang 3.1 (the only compiler I know that implements ref-qualifiers), I get the following output:

    $ clang++ -std=c++0x -stdlib=libc++ -pedantic -Wall t.cpp
    $ ./a.out
    copy ctor // #1
    move ctor // #2

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to create a generic method which can call overloaded methods? I tried but
How can I get the name of the first method called from an expression
Okay, so I realised after writing some overloaded methods that webmethods can't be overloaded
I have some questions as to which overloaded method would be called in certain
How can I invoke overloaded generic method in IronRuby? I have a .NET class
How can I overload a method that takes a Generic List with different types
I noticed today that auto-boxing can sometimes cause ambiguity in method overload resolution. The
I would like to create a class whose methods can be called from multiple
Not many are aware of this feature, but Python's functions (and methods) can have
The RFC for a Java class is set of all methods that can be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.