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

  • Home
  • SEARCH
  • 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 6763619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:29:53+00:00 2026-05-26T14:29:53+00:00

One of our classes provides tr1::function callback object. When I try assigning a member

  • 0

One of our classes provides tr1::function callback object. When I try assigning a member function to it, though, I get a compiler error.

The examples below are untested and just to illustrate:

Foo.h:

class Foo()
{
public:
  Foo();
  std::tr1::function<void (int x)> F;
}

Bar.h:

class Bar()
{
public:
   Bar();
   Foo* foo;
   void HookUpToFoo();
   void Respond(int x);
}

Bar.cpp:

Bar()
{
    this->foo = new Foo();
    this->HookUpToFoo();
}

void Bar::HookUpToFoo()
{
  this->foo->F = &Bar::Respond; // error
}

void Bar::Respond(int x)
{
       // do stuff
}

The compiler error we get refers to a line in xrefwrap and is
Error 1 error C2296: ‘.*’ : illegal, left operand has type ‘int’ C:\Program Files\Microsoft Visual Studio 9.0\VC\include\xrefwrap 64

..What am I doing wrong in assigning a delegate? I want to go the more modern route and use tr1::function rather than function pointers.

  • 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-26T14:29:53+00:00Added an answer on May 26, 2026 at 2:29 pm

    A member function accepts an additional hidden parameter: this. This makes it incompatible with your function object which only accepts one parameter. You can bind a member function to a particular instance using bind, which is also available in tr1:

    using namespace std::tr1::placeholders;
    
    this->foo->F = std::tr1::bind(&Bar::Respond, this, _1);
    

    This ensures that Bar::Respond will be called with the correct value bound to this. The _1 is a placeholder for the additional parameter (x).

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

Sidebar

Related Questions

At our company one of the core C++ classes (Database connection pointer) is implemented
I'm learning C++ for one of my CS classes, and for our first project
I just spent half an one our to find out what caused the Error-Message
One of our programs is sometimes getting an OutOfMemory error on one user's machine,
One of our vendors provides a web service API to allow their customers to
Been getting a NoSuchMethodError on one of our classes on a simple getter method.
I'm using C and ASM{} in one of our classes in order to complete
I'm having trouble compiling one of our legacy COM components. I get the following
I have classes we wrote for one of our customers, to be used in
I came across an issue with one of our utility classes today. It is

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.