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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:07:58+00:00 2026-06-17T01:07:58+00:00

Suppose I have a class A and a class B that is derived from

  • 0

Suppose I have a class A and a class B that is derived from A. Now, I want to cast a const A* (called “a”) to a B* using dynamic_cast (see below). If “a” really was a B*, then my resulting object pointer should be fine. If “a” was not a B*, then I will get NULL.

const A* a = new B();
const B* b = dynamic_cast<const B*>(a);

For some reason, the dynamic_cast operation causes a SEGFAULT. How can that happen if “a” is NOT NULL? I guess that dynamic_cast will give me a NULL pointer if there were any conversion problems, instead of a SEGFAULT. I should only get a SEGFAULT if I am trying to access “b” and the dynamic cast was unsuccessful, right? I have not even tried to access “b” yet.

So, how can this happen? Is there anything that can cause dynamic_cast to SEGFAULT in the above code, that I am not aware of?

Thanks in advance 🙂

EDIT: Running my actual program through GDB gives this output:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) where
#0  0x0000000000000000 in ?? ()
#1  0x00007ffff6c0e612 in __cxxabiv1::__dynamic_cast (src_ptr=<optimized out>, 
src_type=0x4fa6b0, dst_type=0x516bb0, src2dst=0)
at /var/tmp/portage/sys-devel/gcc-4.6.3/work/gcc-4.6.3/libstdc++-v3/libsupc++/dyncast.cc:61

The next line in the output just points to the line in my code where I do the dynamic casting.

  • 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-17T01:07:59+00:00Added an answer on June 17, 2026 at 1:07 am

    Reasons which can cause a crash when using dynamic_cast

    • pointer points to a free memory block.
    • pointer points to a non-polymorphic type.
    • pointer points to an object with a polymorphic type but present in an external library compiled with RTTI disabled.
    • pointer points to a memory accessing which can cause protection exception (such as a guard page or inaccessible page).

    Verify if one of these cases is applicable to you.

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

Sidebar

Related Questions

Suppose that whe have some object, derived from these class instances class A {
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have a Python class that I want to add an extra property
Suppose I have a Base class and a Child class that inherits from Base
Suppose that we have a class called class1. The class1 has a method called
Suppose I have a class Dog that inherits from a class Animal . What
I have a custom control derived from Button: class MyControl : Button{} And suppose,
Suppose we have an interface ICat that is derived from ICatBase and ICatExtension as
Suppose I have a base class and two classes derived from it: class Base
Suppose I have a class derived from a base class. Polymorphism allows me to

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.