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

The Archive Base Latest Questions

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

I found in one article saying static_cast is used for non-polymorphic type casting and

  • 0

I found in one article saying “static_cast is used for non-polymorphic type casting and dynamic_cast is used for polymorphic type casting”. I understand that int and double are not polymorphic types.

However, I also found that static_cast can be used between base class and derived class. What does polymorphic type here mean? Some people says polymorphic type means the base class with virtual function. Is that right? Is this the only situation? What else? Can anybody could elaborate this for me more?

  • 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-13T09:08:08+00:00Added an answer on May 13, 2026 at 9:08 am

    First of all, the article is not completely correct. dynamic_cast checks the type of an object and may fail, static_cast does not check and largely requires the programmer to know what they’re doing (though it will issue compile errors for some egregious mistakes), but they may both be used in polymorphic situations. (dynamic_cast has the additional requirement that at least one of the involved types has a virtual method.)

    Polymorphism in C++, in a nutshell, is using objects through a separately-defined interface. That interface is the base class, and it is almost always only useful to do this when it has virtual methods.

    However, it’s rare-but-possible to have polymorphism without any virtual methods; often this is a sign of either bad design or having to meet external requirements, and because of that, there’s no way to give a good example that will fit here. (“You’ll know when to use it when you see it,” is, unfortunately, the best advice I can give you here.)

    Polymorphism example:

    struct Animal {
      virtual ~Animal() {}
      virtual void speak() = 0;
    };
    
    struct Cat : Animal {
      virtual void speak() { std::cout << "meow\n"; }
    };
    
    struct Dog : Animal {
      virtual void speak() { std::cout << "wouf\n"; }
    };
    
    struct Programmer : Animal {
      virtual void speak() {
        std::clog << "I refuse to participate in this trite example.\n";
      }
    };
    

    Exercising the above classes slightly—also see my generic factory example:

    std::auto_ptr<Animal> new_animal(std::string const& name) {
      if (name == "cat") return std::auto_ptr<Animal>(new Cat());
      if (name == "dog") return std::auto_ptr<Animal>(new Dog());
      if (name == "human") return std::auto_ptr<Animal>(new Programmer());
      throw std::logic_error("unknown animal type");
    }
    
    int main(int argc, char** argv) try {
      std::auto_ptr<Animal> p = new_animal(argc > 1 ? argv[1] : "human");
      p->speak();
      return 0;
    }
    catch (std::exception& e) {
      std::clog << "error: " << e.what() << std::endl;
      return 1;
    }
    

    It’s also possible to use polymorphism without inheritance, as it’s really a design technique or style. (I refuse to use the buzzword pattern here… :P)

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

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 499k
  • 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 Yup. Measure-Command { .\do_something.ps1 } Note that one minor downside… May 16, 2026 at 12:30 pm
  • Editorial Team
    Editorial Team added an answer Given that you only know the type at execution time,… May 16, 2026 at 12:30 pm
  • Editorial Team
    Editorial Team added an answer I am not familiar with the control you mention, but… May 16, 2026 at 12:30 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I found this article: http://www.deluxeblogtips.com/2010/05/editor-style-wordpress-30.html I created a child theme using the Twentyten theme
I recently found out about Presenter First and read their whitepapers and blogs, etc.
I have a website that I made and I am planning to redo it.
I'll like to combine both my initial problem which leads me to this one
I've got a table that is comprised of the following structure. CREATE TABLE [dbo].[tblData](
So, I´ve got an issue that someone might have solved (or so I hope).
Our nightly build process was broken for a long time, such that it generated
Question: Today I worked with MS Visual Sourcesafe, that is to say Microsoft's Sourcecode
Is it possible to establish a set of templated function pointers, without the hassle
I'm new to MVC and I'm implementing the Nerd Dinner MVC sample app in

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.