fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class A {
  5. public:
  6. bool isCompressed() const { return compressed_; }
  7. private:
  8. bool compressed_;
  9. };
  10.  
  11. class B {
  12. private:
  13. class A *a_ptr_;
  14. public:
  15. B() { a_ptr_ = new A; }
  16. ~B() { delete a_ptr_; }
  17. B& operator= (const B x) { *a_ptr_ = *x.a_ptr_; }
  18. const A * filePointer() const {
  19. return a_ptr_;
  20.  
  21. }
  22. };
  23.  
  24. int main() {
  25. B objectB;
  26. if (objectB.filePointer()->isCompressed())
  27. cout<< "yes"<<endl;
  28. const A * objectA = objectB.filePointer();
  29. delete objectA; // OOOOOOPS !!!!!!!!!!! causes segfault !
  30. return 0;
  31. }
Runtime error #stdin #stdout #stderr 0s 3456KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
*** Error in `./prog': double free or corruption (fasttop): 0x09047a10 ***