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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:26:01+00:00 2026-05-11T09:26:01+00:00

I have a class that creates an object inside one public method. The object

  • 0

I have a class that creates an object inside one public method. The object is private and not visible to the users of the class. This method then calls other private methods inside the same class and pass the created object as a parameter:

class Foo {    ... };  class A {    private:       typedef scoped_ptr<Foo> FooPtr;        void privateMethod1(FooPtr fooObj);     public:       void showSomethingOnTheScreen() {           FooPtr fooObj(new Foo);           privateMethod1(fooObj);       }; }; 

I believe the correct smart pointer in this case would be a scoped_ptr, however, I can’t do this because scoped_ptr makes the class non copyable if used that way, so should I make the methods like this:

void privateMethod1(FooPtr& fooObj); 

privateMethod1 doesn’t store the object, neither keeps references of it. Just retrieves data from the class Foo.

The correct way would probably be not using a smart pointer at all and allocating the object in the stack, but that’s not possible because it uses a library that doesn’t allow objects on the stack, they must be on the Heap.

After all, I’m still confused about the real usage of scoped_ptr.

  • 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. 2026-05-11T09:26:01+00:00Added an answer on May 11, 2026 at 9:26 am

    Use here simple std::auto_ptr as you can’t create objects on the stack. And it is better to your private function just simply accept raw pointer.

    Real usage is that you don’t have to catch all possible exceptions and do manual delete.

    In fact if your object is doesn’t modify object and your API return object for sure you’d better to use

    void privateMethod1(const Foo& fooObj); 

    and pass the object there as

    privateMethod1(*fooObj.get()); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer For those blessed with MySQL >= 5.1.12, you can control… May 11, 2026 at 2:26 pm
  • added an answer You can make your own transformation matrices. They don't even… May 11, 2026 at 2:26 pm
  • added an answer You have to add ampersand sign to 'buflisted' to show… May 11, 2026 at 2:26 pm

Related Questions

I'm looking for thoughts on how should I use Session in an ASP.NET MVC
Let's say you have a table containing articles and you want want to display
I have a somewhat ridiculous question regarding DDD, Repository Patterns and ORM. In this
In C#, if you have multiple constructors, you can do something like this: public

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.