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

The Archive Base Latest Questions

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

boost::scoped_ptr documentation contains an example of a technique referred as Handle/Body Idiom. It is

  • 0

boost::scoped_ptr documentation contains an example of a technique referred as Handle/Body Idiom. It is described there in the following words:

The scoped_ptr_example_test.cpp sample program includes a header file,
scoped_ptr_example.hpp, which uses a scoped_ptr<> to an incomplete type
to hide the implementation.

However, at the same time, in the documentation for checked_delete it is stated:

A particularly troublesome case is when a smart pointer’s destructor, such as
boost::scoped_ptr::~scoped_ptr, is instantiated with an incomplete type.
This can often lead to silent, hard to track failures.
The supplied function and class templates can be used to prevent these problems, as they
require a complete type, and cause a compilation error otherwise.

scoped_ptr indeed uses checked_delete in its implementation. To me it looks like the two passages contradict one another. Also, I fail to compile my code that tries to employ the proposed trick with the following message:

checked_delete.hpp:32: error: invalid application of 'sizeof' to 
incomplete type 'MyClass'

So is, indeed, the documentation of scoped_ptr erronous or do I just miss something?

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

    They don’t contradict each other. Because scoped_ptr is a template, and because there is no explicit instantiation in the code, each method is instantiated on demand. That means that the type must be complete by the time that ~scoped_ptr<> is instantiated, which in this case is in the .cpp file after the held type is complete (look for example::~example(){} close to the end of the file, which is where ~scoped_ptr<> is instantiated)

    This is actually an interesting use case for a user defined destructor that looks exactly the same as the compiler generated would, but allows you to control where / when the destruction happens to enable the PIMPL pattern with some smart pointers. If the destructor was not declared and defined, then the destructor would be implicitly defined by the compiler where needed, and the type would be incomplete, causing UB.

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

Sidebar

Related Questions

Why does the following code not allow foo(ptr) to be called ? #include <boost/scoped_ptr.hpp>
I have a question about the following code: #include <iostream> #include <boost/scoped_ptr.hpp> class Interface
I'm trying to write a smart pointer wrapper (contains a boost shared_ptr or scoped_ptr
#include <boost/format.hpp> #include <boost/scoped_ptr.hpp> #include <stdexcept> #include <unordered_map> #include <functional> #define DECLARE_OBJECT(classname) namespace {core::declare_object<classname>
Why is the destructor not invoked in this code? #include <boost/scoped_ptr.hpp> #include <iostream> class
This code fails to compile: namespace boost { template<class T> class scoped_ptr; } namespace
Is there some equivalent class for C++1x's std::unique_ptr in the boost libraries? The behavior
A member of my class is a boost::scoped_ptr which is set to (T*)0 when
When using either boost::scoped_ptr or boost::shared_ptr I get the error 1> * \algomanager.cpp(28) :
Can boost::smart_ptr such as scoped_ptr and shared_ptr be used in polymorphism? class SomeClass {

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.