ç®æ¬¡
ãæ»ãå¤åã®å¾ç½®è¨æ³ãã£ã¦ä½ï¼
C++11ããå°å ¥ãããè¨èªä»æ§ã§ãã ã¿ã¤ãã«ã®å¼ã³æ¹ã¯èªåãåæã«ä½¿ã£ã¦ããã ãã§ãè±èªåã ã¨ãtrailing-return-typeãããã使ããããããã cpprefjp.github.io
ãã®ä»æ§ã使ãã¨ä¾ãã°ä»¥ä¸ã®ãããªã³ã¼ãã
int Add(int a, int b) { return a + b; }
ãã®ããã«ãªãã¾ãã
auto Add(int a, int b) -> int { return a + b; }
ä½ãå¬ããã®ï¼
ãã®ä»æ§ã¯C++ã®ã¡ã¿ããã°ã©ãã³ã°ã§æ»ãå¤åã®æ¨è«ãç°¡åã«è¡ãç®çã§ä½¿ç¨ããã¾ãã
ãªãã ããããªC++ä¸ç´è
ã®ããã®æ©è½ãªãã¦ä¸ã
ã®äººéã«ã¯é¢ä¿ãªãããããã¨ãæãããããã¾ãããããã®æ©è½ã«ã¯ããä¸ã¤ãããããã大ããªã¡ãªãããããã®ã§ãã
ããã¯ãºããª...
é¢æ°åã§ã¤ã³ãã³ããæãããã
ä¾ãã°ä»¥ä¸ã®ãããªã¯ã©ã¹ããã£ãã¨ãã¾ãã
class Human { public: Human(int age, const std::string& name); int GetAge() const; std::string GetName() const; private: int m_age; std::string m_name; };
ãã®ã¯ã©ã¹ã§ã¯ï¼ã¤ã®ã¡ã³ãé¢æ°ãããã¾ãããé¢æ°åã®ä½ç½®ãããã¦ããããæ°æã¡æªããæããããããã¾ããã
class Human { public: Human(int age, const std::string& name); int GetAge() const; std::string GetName() const; private: int m_age; std::string m_name; };
ã¹ãã¼ã¹ãå
¥ãã¦é¢æ°åã®ä½ç½®ãæãã¾ããã
ããï½ãããã°ã©ã ããããã«ãªãã®ã¯æ°æã¡ãããã§ããã
ãï¼åä¾ã®ååã®ä¸è¦§ãåå¾ããã¡ã³ãé¢æ°ã欲ããï¼...ãããããªããªã
class Human { public: Human(int age, const std::string& name); int GetAge() const; std::string GetName() const; std::vector<std::string> GetChildNameList() const; private: int m_age; std::string m_name; std::vector<std::string> m_childNameList; };
æç« ã§èª¬æããã»ããæ©ãã£ãããããã¾ãããã
ã¤ã¾ããé¢æ°ãå®ç¾©ããéã«ãã®ã¾ã¾ä¸¦ã¹ã¦ãã¾ãã¨ãé¢æ°åãæããªãã®ã§å¯èªæ§ãä¸ãã£ã¦ãã¾ãã
ãã¨ãã£ã¦ãé¢æ°åã§æãã¦ãã¾ãã¨ãå¾ã
ååãé·ãæ»ãå¤åã®é¢æ°ã追å ããã¨ãã«å°ã£ã¦ãã¾ããã¨ããã¸ã¬ã³ããèµ·ãã¦ããã®ã§ãã
å¥æ¡ã¨ãã¦æ»ãå¤åã§æ¹è¡ããæ¹æ³ãããã¾ãããè¡æ°ããããã®ã§ã¹ãã¼ãã¨ã¯è¨ãã¾ããã
ããããæ»ãå¤åã®å¾ç½®è¨æ³ãã使ãã¨...
class Human { public: Human(int age, const std::string& name); auto GetAge() const -> int; auto GetName() const -> std::string; auto GetChildNameList() const -> std::vector<std::string>; private: int m_age; std::string m_name; std::vector<std::string> m_childNameList; };
ãã®ï¼ã¤ã®åé¡ãã¹ãã¼ãã«è§£æ±ºãããã¨ãã§ãã¾ãã ããã¤ãåé¡ç¹ãããã¾ãããè¦æ ããããã®ã§èªåã¯æ®æ®µãããã®æ¸ãæ¹ã§å®è£ ãã¦ãã¾ãã
åé¡ç¹
Qï¼æ»ãå¤åãè¦ã¥ãã
Aï¼èãã¦ãã ããã
Qï¼IDEã®èªåçæã対å¿ãã¦ããªã
Qï¼ã¿ã¤ãæ°å¢ããããå«
Qï¼æ¢åã®å®è£
ãæ¸ãæããã®ãã«ã
Aï¼ããã¯ããç¨åº¦ã©ãã«ãã§ããã®ã§æ¬¡åç´¹ä»ãã¾ãã
ï¼è¿½è¨ï¼
解決æ¹æ³ãæ¸ãã¾ããã
rough-paint.hatenablog.com