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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:23:40+00:00 2026-06-16T10:23:40+00:00

So this is probably a weird question, but I have a reasonably good reason

  • 0

So this is probably a weird question, but I have a reasonably good reason for asking.

The gist of my question is, given an example with two levels of derivation on a class hierarchy:

Main Base Class:

class Animal
{
  virtual void Draw() = 0;
};

Derived Class:

class Dog : public Animal
{
  virtual void Draw()
  {
    // draw a generic dog icon or something...
  }
};

Further Derivation:

class Corgi : public Dog
{
  virtual void Draw()
  {
    // draw a corgi icon...
  }
};

Now, I’d love to be able to, from within the Corgi class, permanently downcast the ‘this’ pointer to a Dog pointer and then pass it off somewhere else as an Animal. This other place will then be able to call the Draw function and get the Dog method, not the virtual Corgi method. I know this is strange, but again, I have a vaguely legitimate reason for wanting to do it.

I’ve tried all the different casting operators and haven’t had any luck, but maybe there is a consistent way of pulling this off? In the past I’ve caused myself trouble by not properly using dynamic_cast which resulted in a similar state for a pointer. Perhaps this time I can use that to my advantage?

Edit:
Perhaps the above example doesn’t illustrate clearly the what I’m trying to achieve, so I’ll elaborate with my real goal.

I’m trying to achieve a shorthand for registering base class implementations that link into a scripting system I’ve been using for a while. The scripting system relies on a base class IScriptContext to facilitate access to real-code functions and member variable access. Internally base classes register their member function addresses and member variable addresses which are later dispatched/accessed through lookup tables. I’m in the process of adding proper support for class derivation hierarchies to the scripting system, and I figured being able to isolate the base class versions of these interfaces would help save time and make the whole process cleaner for me when it comes time to register available base classes with the script interpreter. There are other ways to achieve this, such as registering class specific function pointers for each required method for each available base class (e.g. this->Dog::CallFunction, this->Dog::SetMember, this->Dog::GetMember.) However, I figured using an interface would allow me to modify things a bit easier down the road if I ever needed to.

I hope all of that makes some kind of sense.

Thanks!

  • 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-16T10:23:42+00:00Added an answer on June 16, 2026 at 10:23 am

    You have a Corgi object. You can:

    1. Treat it as a Dog object everywhere by using the Dog:: qualifier to all calls (e.g. ptr->Dog::draw();). This loses you virtual dispatch, and is almost certainly not what you want from how your question reads.

    2. Actually construct a new Dog object from your Corgi. Just do this with a normal static_cast as you’d convert any other type or let implicit conversion take over (e.g. Corgi c; Dog d(c);).

    These are the options available to you. To want to retain a Corgi but automatically pretend everywhere that it’s a Dog is neither reasonable nor legitimate, so the language does not provide for it.

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

Sidebar

Related Questions

i have a quite weird question which probably has no practical use but the
This is probably a stupid question but will ask anyway sine I have no
I feel like this is probably a stupid question... but anyway I have this
This is probably a really weird question... but is there a non-git Github? I
This is weird and probably not possible but I'll ask anyway. I'm making this
This probably is a dummy question but I cannot find a clear indication. I
Im sorry for this probably dumm question, but I want to simply open modals
I have a weird thing to do and this would probably imply a weird
probably a weird question, but bear with me (-: when Perl loads a module
This question has probably been asked before, but I am not able to find

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.