cppll ã® [cppll:11457] delete this ãã¡ãã£ããâ¦ãã®ã¹ã¬ããããï¼
C++ã§ï¼ãã¹ãã©ã¯ã¿ã private ã«ããã¨ï¼ã¯ã©ã¹ã®ã¤ã³ã¹ã¿ã³ã¹ãçæããéã«new ãå¼·å¶ã§ããï¼
class Hoge { private: virtual ~Hoge() {} public: void suicide() { delete this; } };
ãã®ããã«ãã¹ãã©ã¯ã¿ãprivate ã«ãã¦ããã¨
Hoge hoge;
ã¯ãã¹ãã©ã¯ã¿ãå¼ã¹ãªãã®ã§ï¼ã³ã³ãã¤ã«æã«ã¨ã©ã¼ã¨ãªãï¼
ã³ã³ãã¤ã«ããã«ã¯
Hoge *hoge=new Hoge;
ã¨newã§çæãããããªãã®ã§ï¼å®å¿ã㦠delete thisããè¡ããã¨ãã訳ï¼ã¸ã¼ï¼
2004/12/26 追è¨
ã©ããä¸è¨æ¹æ³ã«ã¯æãéãããããã§ï¼ãã¹ãã©ã¯ã¿ãépublicã«ããã ãå®å¿ã¯ã§ããªã模æ§ï¼"éããããã§ãã"æ§ï¼å¾¡ææãããã¨ããããã¾ãï¼
ãã¢ã½ã³ã»ã¨ãã¥ã±ã¼ã·ã§ã³
売ãä¸ãã©ã³ãã³ã°: 13972
ããããã°ãè¯ãã£ããã ï¼
å®è·µã«å³ããTipsé
æ¥æ¬èªã«ã¬ãã«ãª
è¯æ¸ãªã®ã«ã»ã»ã»