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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:56:22+00:00 2026-06-07T03:56:22+00:00

I use shared_ptr with constructing an object like this: std::tr1::shared_ptr<RawClusterBase> rawCluster(new RawClusterBase()); // …

  • 0

I use shared_ptr with constructing an object like this:

std::tr1::shared_ptr<RawClusterBase> rawCluster(new RawClusterBase());
// ...
rawCluster->addLabel(p->userFriendlyTerms());
// ...
const TokenizedDocument * tokenizedDoc
   = (TokenizedDocument *)documents.at(i);
const RawDocument * rawDoc
   = dynamic_cast<const RawDocument *>(tokenizedDoc->getProperty(
      TokenizedDocument::_PROPERTY_RAW_DOCUMENT));
rawCluster->addDocument(rawDoc);

I get a segmentation fault on the line with the dynamic_cast:

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b92429 in __dynamic_cast () from /usr/lib/libstdc++.so.6
(gdb) backtrace
#0  0x00007ffff7b92429 in __dynamic_cast () from /usr/lib/libstdc++.so.6
#1  0x0000000000444aa5 in main (argc=1, argv=0x7fffffffe258) at clustering/document_test.cpp:271

Can anybody give me a pointer how to solve that? I have a other section in my project
where I use dynamic_cast to analyze subclass. I also plan to use the shared_ptr there
but I am afraid I would run into the same troubles. Is dynamic_cast not working with shared_ptr?

Any hint is greatly appreciated!

  • 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-07T03:56:23+00:00Added an answer on June 7, 2026 at 3:56 am

    It’s hard to tell what might be going wrong. It could be due to a buffer overrun or access to a deallocated pointer, because such things are likely to overwrite a vtable pointer (which occurs at the beginning of an object). Try running the program in Valgrind.

    Typically dynamic_cast shouldn’t crash. It returns nullptr (or throws std::bad_cast when using references) if the cast is invalid, or it fails to compile if the cast is totally impossible. But it doesn’t invoke UB, so I’d look elsewhere for the culprit.

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

Sidebar

Related Questions

I use std::tr1::shared_ptr extensively throughout my application. This includes passing objects in as function
How can I use std::shared_ptr for array of double? Additionally what are advantages/disadvantages of
Is this the right way, to use boost::shared_ptr for the nodes left and right
I didn't find information about performance issues with auto_ptr and shared_ptr (I use tr1
I would like to use std::make_shared to create a void pointer. Since make_shared is
I am trying to use std::shared_ptr in my code. I have seen there have
I am currently reading through C++ TR1 extensions and started focussing on std::tr1::shared_ptr. So,
I want to use shared_ptr just like I'd use an actual pointer. I wanted
I use boost::shared_ptr in my application in C++. The memory problem is really serious,
I can't use shared_ptr in my project, no boost :( So, I'm having a

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.