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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:03:56+00:00 2026-06-03T05:03:56+00:00

class Whatever { public: virtual ~Whatever(); protected: Whatever(); virtual void SomeMethod(); void OnEventOccurred(int x);

  • 0
class Whatever
{
public:
    virtual ~Whatever();

protected:
    Whatever();
    virtual void SomeMethod();
    void OnEventOccurred(int x);

    std::vector<boost::signals2::scoped_connection> boostSignalConnections_;
}

// .cpp

Whatever::SomeMethod()
{
    ...
    boostSignalConnections_.push_back(
        anObject->AddEventOccurredObserver(
            std::bind(&Whatever::OnEventOccurred,
                      this, std::placeholders::_1)));
    ...
}

(Note AddEventOccurredObserver just delegates to boost::signals2::connect() and returns the boost::signals2::connection)

I’m getting the following error. It’s hard to interpret template errors but it seems like the error is being caused at the member declaration of std::vector<boost::signals2::scoped_connection> boostSignalConnections_;

...\vc\include\xmemory(202): error C2248:  
    'boost::signals2::scoped_connection::scoped_connection' :
    cannot access private member declared in class 'boost::signals2::scoped_connection'
...\boost_1_47\boost\signals2\connection.hpp(234) : see declaration of
'boost::signals2::scoped_connection::scoped_connection'
...\boost_1_47\boost\signals2\connection.hpp(210) :
    see declaration of 'boost::signals2::scoped_connection'
...\vc\include\xmemory(201) : while compiling class template member function
'void std::allocator<_Ty>::construct(boost::signals2::scoped_connection *,_Ty &&)'
with
[
    _Ty=boost::signals2::scoped_connection
]

I’ve searched and I think it might have to do with scoped_connection not being copyable? I’m not sure. The reason I’m using a scoped_connection is because of this SO question:
Handle connection/disconnection of many signals/slots with boost::signals2

Update

FYI, when I change from scoped_connection to connection it works: std::vector<boost::signals2::connection> boostSignalConnections_;. My whole reason for using scoped_connection is that they automatically disconnect the connection on destruction whereas I believe a connection doesn’t not. However, I can just iterate over the collection and manually disconnect each one.

  • 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-03T05:03:58+00:00Added an answer on June 3, 2026 at 5:03 am

    boost::signals2::scoped_connection is non-copyable, and in C++03, std::vector<T> requires that T be both copy-constructible and copy-assignable (this requirement is relaxed in C++11, where a non-copyable type is fine as long as it’s movable instead).

    The naive solution would be to make boostSignalConnections_ a std::vector<scoped_connection*> instead, but this introduces object lifetime and exception-safety issues that aren’t worth the effort. Instead, depending on how recent your compiler is, I’d recommend the following:

    • C++03: Use boost::ptr_vector<scoped_connection>, which will store pointers for you (allowing non-copyable types) but give you value-semantics, and eliminate the aforementioned object lifetime and exception-safety issues.
    • C++11: The above is still a valid option, but the more idiomatic approach would be to use std::vector<std::unique_ptr<scoped_connection>>.

    That being said, why used scoped_connection if you don’t want your object to be lexically-scoped?

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

Sidebar

Related Questions

If I have a class like this: public class Whatever { public void aMethod(int
class foo { public: void say_type_name() { std::cout << typeid(this).name() << std::endl; } };
Say we have Class A { public: int _i; virtual int getI(); }; class
So I'm looking through some code, and I see this: class whatever { public:
class test <T> where T : class { public void Write<T>() { Console.Write(typeof(T).FullName); }
class Widget { public: Widget() { cout<<~Widget()<<endl; } ~Widget() { cout<<~Widget()<<endl; } void* operator
so let's say you have a singleton pattern or whatever: class Smth{ public static
When having: template <typename Super> class Whatever : public Super { ... }; is
Suppose I have the following (simplified case): class Color; class IColor { public: virtual
Let's say I have this: public class Whatever { private ArrayList<String> myList = new

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.