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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:35:47+00:00 2026-05-16T07:35:47+00:00

At work we have a base class, let’s call it IntrusiveBase, that acts something

  • 0

At work we have a base class, let’s call it IntrusiveBase, that acts something like a mixin to allow a class to be stored in a boost:intrusive_ptr. That is, it provides its subclasses with a ref count and defines intrusive_ptr_add_ref and intrusive_ptr_release overloads. The problem is that it is too easy for someone to forget that a particular subclass inherits from IntrusiveBase, and they then store it in some other smart pointer like a scoped_ptr or shared_ptr. That doesn’t work because, for example, the scoped_ptr will delete the object when it goes out of scope no matter what the ref count happens to be. We have an assertion in ~IntrusiveBase that the ref count is one, but this is not foolproof because oftentimes there will end up only being the original instance by the time the scoped_ptr goes out of scope. This leaves an insidious failure waiting to happen those few times that the ref count is not one.

Is there any way that I can cause a compile-time failure if someone accidentally does this? Even if I have to do something repetitively for each of the major smart pointer classes, it would be worth it.

  • 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-16T07:35:48+00:00Added an answer on May 16, 2026 at 7:35 am

    Even if I have to do something repetitively for each of the major smart pointer classes, it would be worth it.

    In that case, you can specialize them on your InstrusiveBase inheriting types.

      namespace boost
      {
        template<>
        class scoped_ptr<InstrusiveBaseSubclass> { }; // scoped_ptr<InstrusiveBaseSubClass> p(new InstrusiveBaseSubClass) won't compile, neither will p->, p.get() etc.
    
      }
    

    This is annoying but it’s macro-able, e..g:

     class A : InstrusiveBase
     { 
         ...
     }
     NO_SCOPED_PTR(A)
     NO_SHARED_PTR(A)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a base class that I want to look like this: class B
Let's say I have a System.Web.IHttpHandler whose base class is ASP.login_aspx whose base class
Okay, so let's say I have some random abstract base class Base and I
Let's say we have: class Base {...} class A : public Base {...} class
I have a base class with a static factory method that makes derived classes:
At my place of work we have a legacy document management system that for
The commandlink link2 does not have work after an ajax call is made to
I have a common base class from which all my ASMX webservice classes will
In my code I have a base class Foo and all my objects inherits
Suppose I have a class Base which has a member variable A* my_hash. 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.