#include <iostream>
using namespace std;
class A {
public:
bool isCompressed() const { return compressed_; }
private:
bool compressed_;
};
class B {
private:
class A *a_ptr_;
public:
B() { a_ptr_ = new A; }
~B() { delete a_ptr_; }
B& operator= (const B x) { *a_ptr_ = *x.a_ptr_; }
const A * filePointer() const {
return a_ptr_;
}
};
int main() {
B objectB;
if (objectB.filePointer()->isCompressed())
cout<< "yes"<<endl;
const A * objectA = objectB.filePointer();
delete objectA; // OOOOOOPS !!!!!!!!!!! causes segfault !
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgQSB7CnB1YmxpYzoKICAgIGJvb2wgaXNDb21wcmVzc2VkKCkgY29uc3QgeyByZXR1cm4gY29tcHJlc3NlZF87IH0KcHJpdmF0ZToKICAgIGJvb2wgY29tcHJlc3NlZF87Cn07CgpjbGFzcyBCIHsKcHJpdmF0ZToKICAgIGNsYXNzIEEgKmFfcHRyXzsKcHVibGljOgogICAgQigpIHsgYV9wdHJfID0gbmV3IEE7IH0gCiAgICB+QigpIHsgZGVsZXRlIGFfcHRyXzsgfSAKICAgIEImIG9wZXJhdG9yPSAoY29uc3QgQiB4KSB7ICphX3B0cl8gPSAqeC5hX3B0cl87IH0gCgljb25zdCBBICogZmlsZVBvaW50ZXIoKSBjb25zdCB7CiAgICAgICAgcmV0dXJuIGFfcHRyXzsKICAgICAgICAKICAgIH0KfTsKCmludCBtYWluKCkgewoJQiBvYmplY3RCOyAKCWlmIChvYmplY3RCLmZpbGVQb2ludGVyKCktPmlzQ29tcHJlc3NlZCgpKSAKCSAgICBjb3V0PDwgInllcyI8PGVuZGw7IAoJY29uc3QgQSAqICBvYmplY3RBID0gb2JqZWN0Qi5maWxlUG9pbnRlcigpOyAKCWRlbGV0ZSBvYmplY3RBOyAgIC8vIE9PT09PT1BTICEhISEhISEhISEhIGNhdXNlcyBzZWdmYXVsdCAhIAoJcmV0dXJuIDA7Cn0=