jeudi 21 mai 2015

Segmentation fault from example in C++ reference for shared_ptr

I took the example code from http://ift.tt/1t4d5sc and compiled it locally, compiled it like this:

g++ -std=c++0x -D_GLIBCXX_USE_NANOSLEEP my_file.cpp 

When I run it, I got the following output:

  Base::Base()
  Derived::Derived()
Created a shared Derived (as a pointer to Base)
  p.get() = 0x608029, p.use_count() = 1
Segmentation fault

Any idea why it has a seg fault?

I'm fairly new to C++, how would you usually debug this?

Thanks!

Aucun commentaire:

Enregistrer un commentaire