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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:52:13+00:00 2026-06-10T13:52:13+00:00

I want to use boost::intrusive_ptr for refcounting my class x::Y , so I add

  • 0

I want to use boost::intrusive_ptr for refcounting my class x::Y, so I add a references field and friend declarations for the release and add_ref functions, which should be defined in namespace boost. Then, I write those functions. Like this:

namespace x{


    class Y{
        long    references;
        friend void boost::intrusive_ptr_add_ref(x::Y * p);
        friend void boost::intrusive_ptr_release(x::Y * p);
    };
}

namespace boost
{
    void intrusive_ptr_add_ref(x::Y * p)
    {
        ++(p->references);
    }

    void intrusive_ptr_release(x::Y * p)
    {
        if (--(p->references) == 0)
            delete p;
    }
}

The code does not compile, I receive the following errors:

test/test6.cpp:8:18: error: ‘boost’ has not been declared
test/test6.cpp:9:18: error: ‘boost’ has not been declared
test/test6.cpp: In function ‘void boost::intrusive_ptr_add_ref(x::Y*)’:
test/test6.cpp:7:11: error: ‘long int x::Y::references’ is private
test/test6.cpp:17:9: error: within this context
test/test6.cpp: In function ‘void boost::intrusive_ptr_release(x::Y*)’:
test/test6.cpp:7:11: error: ‘long int x::Y::references’ is private
test/test6.cpp:22:13: error: within this context

I thought I did everthing like explained by the boost documentation, but it seems that I did something wrong. Where is the problem?

  • 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-06-10T13:52:14+00:00Added an answer on June 10, 2026 at 1:52 pm

    The errors are because you are referring to the boost namespace in your class definition, before any declaration of that namespace. You can fix it by declaring namespace boost before your class definition; you’ll also need to declare the functions, and to do that you’ll also need to declare the class and namespace:

    namespace x {class Y;}
    namespace boost
    {
        void intrusive_ptr_add_ref(x::Y * p);
        void intrusive_ptr_release(x::Y * p);
    }
    

    However, if might be better to put the functions not in the boost namespace, but in the namespace containing your class (i.e. in namespace x). Then intrusive_ptr will find the correct version by argument-dependent name lookup. This doesn’t require any declarations before the class.

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

Sidebar

Related Questions

I want to use boost::thread_specific_ptr but need to know what to add to my
I want to use boost::crc so that it works exactly like PHP's crc32() function.
I want to use boost::timed_wait to wait for an event or to timeout after
I am using boost build in my project and now i want to use
We use Boost statically linked with our app but now I want to use
I want to use Boost C++ in a Windows 8 Metro app and I
I am starting a new c++ project and I want to use Boost.Build /
I want to use boost::bind (I'm not sure if it is really the right
I want to use boost::asio but I don't want boost to throw exceptions, because
I want to use the boost library in a c++ project I'm doing in

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.