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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:33:56+00:00 2026-05-12T07:33:56+00:00

I have a vector of UnderlyingClass pointers stored in another object, and inside a

  • 0

I have a vector of UnderlyingClass pointers stored in another object, and inside a method in UnderlyingClass I want to add the “this” pointer to the end of that vector. When I look at the contents of the vector immediately after the push_back call, the wrong pointer is in there. What could be going wrong?

cout << "this: " << this << endl;
aTextBox.callbacks.push_back(this); 
cout << "size is " << aTextBox.callbacks.size() << endl;
cout << "size-1: " << aTextBox.callbacks[aTextBox.callbacks.size()-1] << endl;
cout << "back: " << aTextBox.callbacks.back() << endl;
cout << "0: " << aTextBox.callbacks[0] << endl;
cout << "this: " << this << endl;
cout << "text box ptr: " << &aTextBox << endl;
cout << "text box callbacks ptr: " << &(aTextBox.callbacks) << endl;

Here’s the output:

this: 0x11038f70
size is 1
size-1: 0x11038fa8
back: 0x11038fa8
0: 0x11038fa8
this: 0x11038f70
text box ptr: 0x11039070
text box callbacks ptr: 0x11039098

By the way, callbacks is a vector of WebCallback pointers, and UnderlyingClass implements WebCallback:

std::vector<WebCallback*> callbacks;


class UnderlyingClass
    :public WebCallback 

Copied from comments: (see Answer below)

output:

this: 0x6359f70 
size is 1 
size-1: 0x6359fa8 
back: 0x6359fa8 
0: 0x6359fa8 
this: 0x6359f70 
WebCallback This: 0x6359fa8 
text box ptr: 0x635a070 
text box callbacks ptr: 0x635a098 

okay, so that explains why the pointers don’t match up.

My real question, then, is this:

how do I get the correct version of a method to be called? Specifically, WebCallback stipulates that a function onWebCommand() be implemented, and right now callbacks[0]->onWebCommand() is not causing the onWebCommand() that I wrote in UnderlyingClass to be executed.

  • 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-12T07:33:56+00:00Added an answer on May 12, 2026 at 7:33 am

    This can happen with multiple inheritance, if your layout looks like this:

    class UnderlyingBase {
      char d[56];
    };
    
    class UnderlyingClass
        :public UnderlyingBase, 
         public WebCallback {
    
    };
    

    Then the layout can be like this, for each object involved. The last one is the complete object containing the first two ones as base-class sub-objects, and that you take the pointer of, and which will be converted to WebCallback*.

    [UnderlyingBase]
     > char[56]: 56 bytes, offset 0x0
    
    [WebCallback]
     > unknown:  x bytes, offset 0x0
    
    [UnderlyingClass]
     > [UnderlyingBase]: 56 bytes (0x38 hex), offset 0x0
     > [WebCallback]:    x  bytes, offset 0x38
    

    Now since your vector contains WebCallback*, the compiler adjusts the pointer to point to the WebCallback sub-object, while when it would point to UnderlyingClass or UnderlyingBase, it would start 0x38 (56) bytes earlier.

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

Sidebar

Ask A Question

Stats

  • Questions 194k
  • Answers 194k
  • 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 Your first and third examples are identical - jQuery offers… May 12, 2026 at 6:46 pm
  • Editorial Team
    Editorial Team added an answer No you can't change the size of an array once… May 12, 2026 at 6:46 pm
  • Editorial Team
    Editorial Team added an answer As an interim solution, I used the approach documented here:… May 12, 2026 at 6:46 pm

Related Questions

I have a vector of integers and I want to convert it to a
I have a vector of myObjects in global scope. I have a method which
I have a vector of myObjects in global scope. std::vector<myObject> A method is passed
I have a vector of pointers that are not owned by the container. How

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.