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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:07:13+00:00 2026-05-23T14:07:13+00:00

Can anybody give me a real world example of a case when dynamic_cast is

  • 0

Can anybody give me a real world example of a case when dynamic_cast is needed and can’t be worked around at all? Examples I can think of can generally be worked around with double dispatch.

If the constraint is too strong, an example where dynamic_cast is generally the way to go would also be nice.

I’d like to see real examples instead of “it’s normally used to cast between types up and down a type tree”.

  • 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-23T14:07:13+00:00Added an answer on May 23, 2026 at 2:07 pm

    Double dispatch requires that the types that are interacting have intimate knowledge of each other’s innards, as it requires that one class call methods on the other class. dynamic_cast works when you cannot modify the innards of a class, or do not wish to break encapsulation of the classes in question.

    That is, double dispatch is invasive on the classes involved, while dynamic_cast works without knowledge of the cast in the classes.

    You can also use dynamic_cast if you don’t know the target method overload which will be invoked. For an example, see this question I posted yesterday.

    Finally, double dispatch does not come without it’s own headaches

    The base class Shape must know about all the derived classes, resulting in circular dependencies. If you derive a new class from Shape (say Triangle), you must update the interface of Shape and the interface/implementation of all the other derived classes. In some cases this is not even an option: you may not have the source code for Shape, or not be willing or permitted to modify it.

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

Sidebar

Related Questions

Can anybody give me an example how to implement AttachedCommands? There are some examples
Can anybody give any working example of how to read/write Unicode text files using
Can anybody give me a little advice please? I have a string, for example
Can anybody give me an example how to use the osgi framework classes? I
Can anybody give an example of c++ code that can easily convert a decimal
Can anybody give me some examples and brief explanation of parallel computing in image
Can anybody give me example that NSMutableArray is thread safe or not?
can anybody give me some example?
Can anybody give me an example how to load the module? For example if
I want to design the following UI. Can anybody give me an example or

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.