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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:30:15+00:00 2026-06-05T18:30:15+00:00

#include <boost/smart_ptr.hpp> class Base { }; class Derived : public Base { public: Derived()

  • 0
#include <boost/smart_ptr.hpp>

class Base {
};

class Derived : public Base {
  public:
    Derived() : Base() {}
};

void func(/*const*/ boost::shared_ptr<Base>& obj) {
}

int main() {
  boost::shared_ptr<Base> b;
  boost::shared_ptr<Derived> d;
  func(b);
  func(d);
}

This compiles with the const in func’s signature but not without it. The error appears in the line with the call func(d);

Any hints 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-06-05T18:30:16+00:00Added an answer on June 5, 2026 at 6:30 pm

    When reading the documentation of boost::shared_ptr we find the following:

    A shared_ptr<T> can be implicitly converted to shared_ptr<U> whenever T* can be implicitly converted to U*.


    This means that boost::shared_ptr<Derived> is implicitly convertable to an object of type boost::shared_ptr<Base>.

    When this conversion takes place upon executing func (d) a temporary will be created, though non-const references cannot be bound to temporary objects – which is why your compiler issues an error unless you make the argument to func a const&.

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

Sidebar

Related Questions

I have the following code: #include <iostream> #include boost/shared_ptr.hpp using boost::shared_ptr; class Base {
Please consider the following simplified example: #include boost/shared_ptr.hpp #include boost/smart_ptr/enable_shared_from_this.hpp using namespace boost; class
Consider the following example: #include Python.h #include <boost/python.hpp> #include <boost/shared_ptr.hpp> class A {}; class
I have the following code: #include <boost/shared_ptr.hpp> struct Foo { int a; }; static
#include <cstdlib> #include <iostream> #include <boost/bind.hpp> #include <boost/asio.hpp> using boost::asio::ip::tcp; class session { public:
I have the following code: #include <boost/smart_ptr/shared_ptr.hpp> #include <boost/numeric/interval.hpp> #include <boost/math/distributions/students_t.hpp> using namespace boost::numeric;
#include <iostream> #include <algorithm> #include <vector> #include <boost/array.hpp> #include <boost/bind.hpp> int main() { boost::array<int,
MinGw 4.7.0 Boost 1.47 code: #include <iostream> #include <boost/thread.hpp> int main(int argc, char *argv[])
Why do I receive the following error for the following code? 1>C:\Libs\boost_1_44\boost/smart_ptr/shared_ptr.hpp(259): error C2683:
#include <boost/chrono.hpp> int main() { boost::chrono::high_resolution_clock::time_point start = boost::chrono::high_resolution_clock::now(); //burn some time boost::chrono::nanoseconds ns

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.