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 6937175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:19:45+00:00 2026-05-27T12:19:45+00:00

Is there anyway in C++11 to have an input argument to a function be

  • 0

Is there anyway in C++11 to have an input argument to a function be declared as invalid after the function returns?

For a simple example, consider that I have a rectangle object with a coordinate for the lower left corner and a coordinate for the upper right corner. If I pass this rectangle object by non-const reference to the function, the function is free to side-effect the rectangle memory in place as it sees fit. What if that function needs to scale it and rather than copying to new memory just wants to work in place, how could we in C++11 declare that after the function returns, the contents of the rectangle passed in are no longer valid as they may have been modified by the function called?

I would not want to modify the rectangle class, but instead have some way in the declaration of the function call to indicate that the memory passed in by reference should be considered invalid upon return from the function and have the compiler give an error if the caller tries to use it subsequent to the function call returning. Is there some way to do this in C++11?

  • 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-27T12:19:46+00:00Added an answer on May 27, 2026 at 12:19 pm

    You can get half-way there:

    void function(rectangle&& x) // r-value reference
    {
        // ...
    }
    
    rectangle r;
    
    function(r); // error
    function(std::move(r)); // okay, explicitly made into an rvalue
    
    // now (by convention) r shouldn't be used, because it's been moved
    

    That said, the type-system is C++ is not strong enough to give you an error if you use it again.

    I question your design, though. What’s wrong with making a copy? Or why not make it clear in the function name that the argument is going to modified? (Like std::swap.)

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

Sidebar

Related Questions

Is there anyway to find the date difference in php? I have the input
In Java is there anyway to have one constructor that will accept an array
I have enter date text input field in my registration form. Is there anyway,
I have a method that takes a System.Web.UI.Page as an input and returns some
Is there any way to have a Windows batch file directly input SQL statements
Is there anyway to have a sort of virtual static member in C++? For
Is there anyway to have items in an ASP.NET DropDownList have either their Text
Is there anyway to have the var be of a nullable type? This implicitly
Is there anyway to have javascript run when a XSL sheet has been applied
Is there anyway in XAML only to have a linebreak in a TextBox? I

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.