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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:34:30+00:00 2026-05-15T08:34:30+00:00

I have some code which use ‘this’ pointer of class which calls this code.

  • 0

I have some code which use ‘this’ pointer of class which calls this code. For example:

Some::staticFunction<templateType>(bind(FuncPointer, this, _1));

Here is I’m calling bind function from boost. But it doesn’t matter. Now I have to wrap this code. I made a macro:

#define DO(Type, Func) Some::staticFunction<Type>(bind(FuncPointer, this, _1));

And compiler insert this code into class which calls this macro, so ‘this’ takes from caller. But I don’t want to use macro and prefer function (inline). But how to resolve ‘this’ passing. Could I use it in inline function like in macro or I have to pass it manually?

  • 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-15T08:34:31+00:00Added an answer on May 15, 2026 at 8:34 am

    The this keyword can be put by the function you call

    class MyClass {
      // ...
      template<typename Type, typename Func>
      void doit(Func f) {
        Some::staticFunction<Type>(bind(f, this, _1));
      }
    };
    

    After which you can call

    doit<templateType>(FuncPointer);
    

    If you like you can inherit the function

    // T must be a derived class of MyRegister<T>
    template<typename T>
    class MyRegister {
    protected:
      template<typename Type, typename Func>
      void doit(Func f) {
        Some::staticFunction<Type>(bind(f, (T*)this, _1));
      }
    };
    
    class MyClass : MyRegister<MyClass> {
      // ...
    };
    

    That way you can just use doit and not first write it, just like with the macro. Useful if you have a wide range of classes that you use the function in.

    Edit: Notice that the C-Style cast is required here (can’t use static_cast), because of the private inheritance. It’s a safe cast if T is derived from MyRegister<T>


    Personally i would prefer this over the macro. Notice that your macro can’t cope with commas in the type-name

    DO(std::pair<A, B>, g);
    

    This tries to pass 3 arguments to the macro instead of 2. You could reverse the order of the type and the function and use variadic macros (which are a C++0x feature, but available in some compiler in C++03 mode) or you could use a typedef and pass the alias name.

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

Sidebar

Ask A Question

Stats

  • Questions 472k
  • Answers 472k
  • 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 As I pointed in this question line separator does not… May 16, 2026 at 3:34 am
  • Editorial Team
    Editorial Team added an answer Something like this? [<System.Runtime.CompilerServices.ExtensionAttribute>] module public StringHelper = [<System.Runtime.CompilerServices.ExtensionAttribute>] let… May 16, 2026 at 3:34 am
  • Editorial Team
    Editorial Team added an answer You can use bracket notation (instead of dot notation), like… May 16, 2026 at 3:34 am

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.