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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:18:46+00:00 2026-06-03T01:18:46+00:00

While I see a plethora of Stack Overflow Questions and Answers for virtual functions

  • 0

While I see a plethora of Stack Overflow Questions and Answers for virtual functions calling their sub/superclass functions of similar name, I’m getting this:

CCLog("Yay"); //ensure it's called
CCScene * tScene = TitleDescription::scene(); //grab the scene

TitleDescription * t = reinterpret_cast<TitleDescription *>(tScene); //Unsure why this even works when I think about it, a scene is returned but the below call:

t->loadWithDataFrom("Information.xml", "story"); //calls setScaleX on CCObject instead.

CCDirector::sharedDirector()->replaceScene(tScene ); //runs with an empty scene on one condition

The condition that the scene loads with loadWithData is that I make the function void name(types). I followed cocos2d-x’s pattern and used virtual, and in that case, it calls setScaleX instead, I used the debugger and stepped into it.

I have two questions.

1) If the scene() function returns a scene (with a child node of the TitleDescription type), then how is this call even functioning (when nonvirtual and running as I want, eg: calling the right function) ?

2) When it messes up, is the vTable just pointing to a garbage location, that happens to always be the same function?

Note: In cocos2d (and X), scenes are subclasses of layers, which subclass CCObject. CCObject does containe the function that gets called, but the name and parameters differ a lot, and I’m not getting why a function, whose name and params will be completely different, gets called.

I’m open to any references and good documentation on this. I’m suspicious that my cast (set to reinterpret just to force-bypass everything), is possibly why the virtual function is pointing to the same function every run, including when I change the signature to bool instead of void, and clean the build.

Note: XCode is the environment I’m in. I don’t believe it’s using LLVM yet either. I will try tweaking that and seeing what happens.

Like everyone else, I don’t think I fully understand vFunctions, even though I’m aware of the use of abstract classes and forced overriding. (Being the first class with that func, I don’t see why it needs to be virtual at this time, but I do plan on extending the function in subclasses due to what I’m doing).

Thanks,
Steve J

  • 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-06-03T01:18:48+00:00Added an answer on June 3, 2026 at 1:18 am

    reinterpret_cast will not downcast correctly. Remember that the base subobject may not be at the beginning of the complete object.

    Use implicit conversion for upcasts, and static_cast or dynamic_cast for downcasts, and dynamic_cast for crosscasts. They will include the appropriate offset when needed and not just return the same address the way reinterpret_cast does.

    And none of these will get you between a parent and member (non-base) subobject.

    Avoiding casts altogether is by far the best.

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

Sidebar

Related Questions

While I see the relevance of web in the phrase web stack, I'm left
In Xcode, GDB allows you to change local variables while debugging (see how to
While browsing SO I sometimes see EOFD for example: ftp -vn <$hostname> <<EOFD Yes
While trying to compile a 64 bit linux kernel using gcc, I see the
While debugging jQuery apps that use AJAX, I often have the need to see
While the NSCurrentLocaleDidChangeNotification perfectly makes sense on Mac OS X, I don't see how
While reset and checkout have different usages most of the time, I can't see
While developing my ASP.NET MVC, I have started to see the need for a
I need to see the contents of a std::map variable while debugging. However, if
I can only see inline CSS and JS while viewing the source code of

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.