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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:09:25+00:00 2026-05-23T18:09:25+00:00

I have the following code which compiles and runs fine under Visual Studio 2008

  • 0

I have the following code which compiles and runs fine under Visual Studio 2008 SP1.

#include <functional>
#include <iostream>

#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/utility.hpp>

class NoncopyableObject : public boost::noncopyable
{
public:
    NoncopyableObject(int x) : x_(x) {}
    int getValue() const {return x_;}
private:
    int x_;
};

template<class F>
class MenuItemDispatcher
{
public:
    MenuItemDispatcher(F f) : f_(f) { }

    void operator ()(NoncopyableObject& w) const
    {
        // Invoke the functor
        f_(w);
    }
private:
    typedef boost::function1<void,NoncopyableObject&> FUNC;
    FUNC f_;
};

void MenuItem()
{
    std::cout << "in MenuItem()\n";
}

template<class F>
MenuItemDispatcher<F> MakeMenuItemDispatcher(F f)
{
    return MenuItemDispatcher<F>(f);
}

int main()
{
    NoncopyableObject obj(7);
    MakeMenuItemDispatcher(boost::bind(&MenuItem))(obj);
}

If I change the boost::bind to std::tr1::bind in main(), I get an error:

error C2248: 'boost::noncopyable_::noncopyable::noncopyable' : cannot access private member declared in class 'boost::noncopyable_::noncopyable'.

This diagnostic occurred in the compiler generated function 'NoncopyableObject::NoncopyableObject(const NoncopyableObject &)'

So it’s trying to generate a copy constructor for NoncopyableObject. Anyone know why this might be so please? MenuItemDispatcher’s call operator takes a reference to a NoncopyableObject, so I am struggling to see what’s going wrong.

  • 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-23T18:09:26+00:00Added an answer on May 23, 2026 at 6:09 pm

    This appears to be a difference in how bind is implemented in MS Visual Studio (including 2010) and GNU gcc (I tested 4.4.1 and 4.5.2, both of which work the way you expected)

    Consider the following code, given your definitions

    auto b = boost::bind(&MenuItem);
    NoncopyableObject obj(7);
    b(obj);  // OK in VS and GCC
    

    replacing boost::bind with std::bind (I’m using 2010, the error message appears to be the same as in your 2008)

    auto b = std::bind(&MenuItem);
    NoncopyableObject obj(7);
    b(obj);  // compile error in VS 2010 SP1, OK in GCC
    b(std::reference_wrapper<NoncopyableObject>(obj)); // OK in both
    

    So, what happens is that MS’s bind() makes a copy of its argument even if the argument is not going to be used, while boost’s and GCC’s bind() does not bother with that argument at all.

    I was able to get your example to compile and run (on 2010) by changing the FUNC typedef to

    typedef boost::function1<void, std::tr1::reference_wrapper<NoncopyableObject> > FUNC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code which compiles and works as expected: #include <iostream>
I have the following code which assembles and runs fine on Windows XP 32
I have the following code which works just fine when the method is POST,
I have the following code which works fine. However, I only want to return
I have the following code which compiles with no warnings (-Wall -pedantic) with g++
I have a ATL COM service exe (MyService.exe), which compiles and runs fine. If
Lets say we have the following code: #include <iostream> #include <string> struct A {
I'm trying to use opengl in C#. I have following code which fails with
I have following Code Block Which I tried to optimize in the Optimized section
Okay so I have the following Code which appends a string to another 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.