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

  • Home
  • SEARCH
  • 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 4252612
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T04:49:06+00:00 2026-05-21T04:49:06+00:00

Is there a way to code into the signature of a method, whether the

  • 0

Is there a way to code into the signature of a method, whether the object owner-ship changes or not? In Getter() and Setter() which take or return pointers, you never know if the object ownership changes or not.

What do you think about:

// Uses pConfiguration or creates its own copy - the ownership is un-touched
void ContainerClass:SetConfiguration( const Configuration* pConfiguration ) {}
// Takes the ownership of pConfiguration (and deletes it in the destructor)
void ContainerClass:PutConfiguration( Configuration* pConfiguration ) {}
// Returns a 'reference' and keeps the ownership (you must not delete it)
const Configuration* ContainerClass::GetConfiguration() {}
// Returns a _new_ object and transfers the ownership to you
Configuration* ContainerClass::TakeConfiguration() {}

So is Set() vs. Put() and Get() vs. Take() a way to code it, or would you use the type (const vs. non-const) – or do you know it from the context?

Best Regards,

Charly

  • 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-21T04:49:07+00:00Added an answer on May 21, 2026 at 4:49 am

    The best way of identifying in an interface that ownership is not changed is by not using pointers. Prefer references to pointers:

    // Does not take ownership
    void ContainerClass::SetConfiguration( const Configuration& config ) {}
    
    // Does not release ownership
    const Configuration& ContainerClass::getConfiguration() const {}
    

    When you need to actually transfer ownership of memory it is better documenting it by names. If you really feel the crave to make it explicit in the signature, use the good-old std::auto_ptr:

    void ContainerClass::SetConfiguration( std::auto_ptr<Configuration> cfg );
    std::auto_ptr<Configuration> ContainerClass::CopyConfiguration() const;
    

    The std::auto_ptr has the weird property that copy actually means transfer the ownership.

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

Sidebar

Related Questions

Is there a way to complie code directly into Native Code instead of MSIL
Is there a simple way of putting source code into a repository and then
Is there a way to paste a block of code into IDLE ? Pasting
Is there a way of assembling x86 code into COM executables? I am using
Is there a way to put your own code into namespaces using cakephp? The
Is there a way I can write a code into a batch file that
Is there a way to enable code outlining for Classic ASP in Visual Studio
Is there way in next piece of code to only get the first record?
Is there a way to reformat code, i.e. force correct indentation in FlashDevelop as
Is there a way to execute code after each Terminal? So that something like

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.