#include <iostream>
class Hoge{
Hoge(){std::cout<<"new"<<std::endl;}
Hoge(Hoge const &);
Hoge& operator=(Hoge const &);
~Hoge(){std::cout<<"del"<<std::endl;}
public:
static Hoge* Create(){return new Hoge();}
static void Delete(Hoge* p){delete p;}
void f(){std::cout<<"f"<<std::endl;}
void f()const{std::cout<<"f const"<<std::endl;}
};
class HogePtr{
Hoge* p;
HogePtr(const HogePtr&);
HogePtr& operator=(const HogePtr&);
public:
HogePtr(Hoge* ap):p(ap){}
~HogePtr(){Hoge::Delete(p);}
Hoge& operator*(){return *p;}
const Hoge& operator*() const {return *p;}
Hoge* operator->(){return p;}
const Hoge* operator->() const{return p;}
};
int main(){
HogePtr p(Hoge::Create());
p->f();
const HogePtr p2(Hoge::Create());
p2->f();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgSG9nZXsKICAgSG9nZSgpe3N0ZDo6Y291dDw8Im5ldyI8PHN0ZDo6ZW5kbDt9CiAgIEhvZ2UoSG9nZSBjb25zdCAmKTsKICAgSG9nZSYgb3BlcmF0b3I9KEhvZ2UgY29uc3QgJik7CiAgIH5Ib2dlKCl7c3RkOjpjb3V0PDwiZGVsIjw8c3RkOjplbmRsO30KcHVibGljOgogICBzdGF0aWMgSG9nZSogQ3JlYXRlKCl7cmV0dXJuIG5ldyBIb2dlKCk7fQogICBzdGF0aWMgdm9pZCBEZWxldGUoSG9nZSogcCl7ZGVsZXRlIHA7fQogICB2b2lkIGYoKXtzdGQ6OmNvdXQ8PCJmIjw8c3RkOjplbmRsO30KICAgdm9pZCBmKCljb25zdHtzdGQ6OmNvdXQ8PCJmIGNvbnN0Ijw8c3RkOjplbmRsO30KfTsKCmNsYXNzIEhvZ2VQdHJ7CiAgIEhvZ2UqIHA7CiAgIEhvZ2VQdHIoY29uc3QgSG9nZVB0ciYpOwogICBIb2dlUHRyJiBvcGVyYXRvcj0oY29uc3QgSG9nZVB0ciYpOwpwdWJsaWM6CiAgIEhvZ2VQdHIoS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