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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:40:32+00:00 2026-05-27T23:40:32+00:00

could you please help me. I am passing self to a pure virtual function

  • 0

could you please help me.
I am passing self to a pure virtual function of itself.

n->dataCallback(handler, n, hangup);

where n is my class pointer and dataCallback is its own (pure) virtual function (I know it makes no sense, I just wonder why it happens what I describe below).

so now in the declaration:

void MyClass::dataCallback(int handler, void *cbData, bool hangup) {
    MyClass *This = (MyClass*) cbData;
 ....
}

Now when I compare This (the varaiable above) to this (the pointer of the object) at runtime I get:

  1. The values of the poiners (the addresses of the object) are different.
  2. When checking a memeber varaible (This->member) I find different values in them. (The correct value is in this, whereas This contains an undefined (to me random) value. Note, that on the caller side the value is of course correct so it seems to magically change during the call itself, and there is no other code in between.

How on earth is this possible? Any Idea?

I’ve spent 2 hours meditating on this, also asked other programmers with no results.

  • 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-27T23:40:32+00:00Added an answer on May 27, 2026 at 11:40 pm

    If you have multiple inheritance, casting a pointer to each of the parent classes may change the pointer address. Consider the following:

    class A
    {
    public:
        int a;
    };
    
    class B
    {
    public:
        int b;
    };
    
    class C : public A, B
    {
    };
    

    The internal layout of class C will contain two integers a and b. If you cast a pointer from C* to A* all is well. If you cast it to B*, the pointer will need to be adjusted because the first element in a B must be the integer b!

    If you do a cast where both types are known to the compiler, it will do the adjusting in a way which is invisible to you – it just works. The compiler knows what the proper adjustment should be. When you cast to void* this mechanism gets broken.

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

Sidebar

Related Questions

Could you please help me to get image upload working on a view with
Could you please help me how to format a struct timeval instance to human
Could someone please help me in here, I'm just a beginner who want to
Could you please help me find out the time complexity of the Fleury' algorithm
Could somebody please help me get Clang up and running? (I don't have 3.2)
Could someone please help explain why I can't get this to work? I properly
Hi Guys could you please help me refactor this so that it is sensibly
Ok so could anyone please help me out with the VB for auto entering
Could anyone please tell how jre directory help in the running java programs? I'm
I've recently written this with help from SO. Now could someone please tell me

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.