++ ãå¾ç½®ããåç½®ã§ä½¿ãçç±
ããªãã @rayfillããã«教えてもらったã®ã§ã
ããããåç½®ã¨å¾ç½®ã¯ã©ãéã
åç½®ã¯ã¤ã³ã¯ãªã¡ã³ãããå¾ã®ç¶æ ãè¿ããå¾ç½®ã¯ã¤ã³ã¯ãªã¡ã³ãããåã®ç¶æ ãè¿ãã
int a = 3, b = 3; cout << ++a // 4 << b++ // 3 << endl;
å¾ç½®ã¯å¤æ´åã®å¤ãä¿æããå¿ è¦ããã
ãªããã®ã¯ã©ã¹ã§å¾ç½®ã® ++ ãå®ç¾©ããã¨ãããªé¢¨ã«ãªãã
// int ã®ããã¼å¼æ°ãåãåãããã«ããã¨å¾ç½®ã® ++ ããªã¼ãã¼ãã¼ã MyClass MyClass::operator++ (int) { MyClass before = *this; //å¤æ´åã®å¤ãä¿å ... //èªåãã¤ã³ã¯ãªã¡ã³ã return before; //å¤æ´åã®å¤ãè¿ã }
ã³ãã¼ã³ã³ã¹ãã©ã¯ã¿ãåã
MyClass before = *this;
㧠*this ã¨åãå 容ã®æ°ããã¤ã³ã¹ã¿ã³ã¹ãä½ãããã£ã¦ããã¨ã¯æ°ããã¤ã³ã¹ã¿ã³ã¹ãä½ã£ã¦ãå ã®ã¤ã³ã¹ã¿ã³ã¹ã®åã¡ã³ããæ°ããã¤ã³ã¹ã¿ã³ã¹ã®ã¡ã³ãã«çªã£è¾¼ãããããªãã¨ã
å¾ç½®ã ã¨åç½®ã¨æ¯ã¹ã¦ãã®å¦çã追å ã§å¿ è¦ã«ãªããã§ãå¿ è¦ããªãéãåç½®ã§æ¸ã¾ãæ¹ãã¨ã³ãã¸ã¼ã