#include <cstdio>
#include <memory>
struct base
{
base( int i ) : i( i)
{
printf ( "base ctor\n " ) ;
}
~base( )
{
printf ( "base non-virtual dtor\n " ) ;
} // non-virtual
int i;
} ;
struct derived : public base
{
char * s;
derived( int i) : base( i) , s( new char [ i] )
{
printf ( "derived ctor\n " ) ;
}
~derived( )
{
printf ( "derived dtor\n " ) ;
delete [ ] s;
}
} ;
int main( )
{
printf ( "Success\n " ) ;
//raw pointer
printf ( "RAW-POINTER\n " ) ;
{
base* b = new derived( 2 ) ;
delete b;
}
printf ( "---END-RAW-POINTER--\n " ) ;
//unique-ptr
printf ( "UNIQUE_PTR\n " ) ;
{
std:: unique_ptr < base> bu( new derived( 3 ) ) ;
}
printf ( "--END-UNIQUE_PTR--\n " ) ;
return 0 ;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPG1lbW9yeT4KCgpzdHJ1Y3QgYmFzZQp7CiAgICBiYXNlKCBpbnQgaSApOiBpKGkpCiAgICB7CiAgICAgICAgcHJpbnRmKCJiYXNlIGN0b3JcbiIpOwogICAgfQogICAgfmJhc2UoKQogICAgewogICAgICAgIHByaW50ZigiYmFzZSBub24tdmlydHVhbCBkdG9yXG4iKTsKICAgIH0gLy8gbm9uLXZpcnR1YWwKICAgIGludCBpOwp9OwoKc3RydWN0IGRlcml2ZWQgOiBwdWJsaWMgYmFzZQp7CiAgICBjaGFyKiBzOwogICAgZGVyaXZlZChpbnQgaSk6IGJhc2UoaSksIHMobmV3IGNoYXJbaV0gKQogICAgewogICAgICAgIHByaW50ZigiZGVyaXZlZCBjdG9yXG4iKTsKICAgIH0KICAgIH5kZXJpdmVkKCkKICAgIHsKICAgICAgICBwcmludGYoImRlcml2ZWQgZHRvclxuIik7CiAgICAgICAgZGVsZXRlIFtdIHM7CiAgICB9Cn07CgppbnQgbWFpbigpCnsKICAgIHByaW50ZigiU3VjY2Vzc1xuIik7CiAgICAKICAgIC8vcmF3IHBvaW50ZXIKICAgIHByaW50ZigiUkFXLVBPSU5URVJcbiIpOwogICAgewogICAgICAgIGJhc2UqIGIgPSBuZXcgZGVyaXZlZCgyKTsKICAgICAgICAKICAgICAgICAKICAgICAgICBkZWxldGUgYjsKICAgIH0KICAgIHByaW50ZigiLS0tRU5ELVJBVy1QT0lOVEVSLS1cbiIpOwogICAgCiAgICAvL3VuaXF1ZS1wdHIKICAgIHByaW50ZigiVU5JUVVFX1BUUlxuIik7CiAgICB7CiAgICAgICAgc3RkOjp1bmlxdWVfcHRyPGJhc2U+IGJ1KCBuZXcgZGVyaXZlZCgzKSApOwogICAgfQogICAgcHJpbnRmKCItLUVORC1VTklRVUVfUFRSLS1cbiIpOwogICAgCiAgICAKICAgIHJldHVybiAwOwp9Cg==