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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:45:44+00:00 2026-05-11T16:45:44+00:00

I am using boost::signal in a native C++ class, and I now I am

  • 0

I am using boost::signal in a native C++ class, and I now I am writing a .NET wrapper in C++/CLI, so that I can expose the native C++ callbacks as .NET events. When I try to use boost::bind to take the address of a member function of my managed class, I get compiler error 3374, saying I cannot take the address of a member function unless I am creating a delegate instance. Does anyone know how to bind a member function of a managed class using boost::bind?

For clarification, the following sample code causes Compiler Error 3374:

#include <boost/bind.hpp>

public ref class Managed
{
public:
    Managed()
    {
        boost::bind(&Managed::OnSomeEvent, this);
    }

    void OnSomeEvent(void)
    {
    }
};
  • 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-11T16:45:44+00:00Added an answer on May 11, 2026 at 4:45 pm

    While your answer works, it exposes some of your implementation to the world (Managed::OnSomeEvent). If you don’t want people to be able to raise the OnChange event willy-nilly by invoking OnSomeEvent(), you can update your Managed class as follows (based on this advice):

    public delegate void ChangeHandler(void);
    typedef void (__stdcall *ChangeCallback)(void);
    
    public ref class Managed
    {
    public:
        Managed(Native* Nat);
        ~Managed();
    
        event ChangeHandler^ OnChange;
    
    private:
        void OnSomeEvent(void);
        Native* native;
        Callback* callback;
        GCHandle gch;
    };
    
    Managed::Managed(Native* Nat)
     : native(Nat)
    {
        callback = new Callback;
    
        ChangeHandler^ handler = gcnew ChangeHandler( this, &Managed::OnSomeEvent );
        gch = GCHandle::Alloc( handler );
        System::IntPtr ip = Marshal::GetFunctionPointerForDelegate( handler );
        ChangeCallback cbFunc = static_cast<ChangeCallback>( ip.ToPointer() );
    
        *callback = native->RegisterCallback(boost::bind<void>( cbFunc ) );
    }
    
    Managed::~Managed()
    {
        native->UnregisterCallback(*callback);
        delete callback;
        if ( gch.IsAllocated )
        {
            gch.Free();
        }
    }
    
    void Managed::OnSomeEvent(void)
    {
        OnChange();
    }
    

    Note the alternate bind<R>() form that’s used.

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

Sidebar

Ask A Question

Stats

  • Questions 303k
  • Answers 304k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer See: C# Converting List<int> to List<double> The cast uint ->… May 13, 2026 at 8:44 pm
  • Editorial Team
    Editorial Team added an answer You can use the normal CI session handling done in… May 13, 2026 at 8:44 pm
  • Editorial Team
    Editorial Team added an answer Here's how I've handled this situation: When the app starts… May 13, 2026 at 8:44 pm

Related Questions

I'm using boost::signals and leaking memory when I try to connect multiple signals to
I am using boost::any to store pointers and was wondering if there was a
I am using boost build in my project and now i want to use
I am using Boost with Visual Studio 2008 and I have put the path

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.