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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:17:11+00:00 2026-05-15T16:17:11+00:00

In my new project I wish to (mostly for to see how it will

  • 0

In my new project I wish to (mostly for to see how it will work out) completely ban raw pointers from my code.

My first approach was to let all classes inherit from this simple class:
template
class Base
{
public:
typedef std::shared_ptr ptr;
};

And simple use class::ptr wherever I need a pointer.

This approach seemed suitable until I realized sometimes my objects wish to pass the ‘this’ pointer to other objects. Letting my objects just wrap it inside a shared_ptr won’t do since then there could be two owners for the same pointer. I assume this is bad.

My next idea was to change the ‘Base’ class to implement reference counting itself, thus every instance of classes that inherits from ‘Base’ can only have one count.

Is this a good solution, are there any better and can boost and/or stl already solve this problem for me?

  • 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-15T16:17:12+00:00Added an answer on May 15, 2026 at 4:17 pm

    You may want to take a look at enable_shared_from_this.

    On another note, when using shared_ptr, you need to be aware of the possibility of circular references. To avoid this, you can use weak_ptr. This means you will need some way to distinguish between the two of them, so simply having a typedef class::ptr may not suffice.

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

Sidebar

Related Questions

I wish to use Entity Framework Code-first for a new project. So i decided
I will start new project which is based on ASP.NET MVC 3 using C#
In a new project of mine I cannot see the Deployment Assembly link in
Tomorrow I will kick off a new project, a line of business application for
I am wanting to start a new (open source) project, and I wish for
I'm new with Azure. I used publishing from Visual Studio to deploy my project
How do I reference another project which has code I wish to leverage in
After initiating a new project, I would like to know when Petrel has completed
It's a brand new project. Here's the exact commands I've run: rails new MyProject
we are starting a new project and I would like to know if V5

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.