10:59 ๋ฉค๋ฒ ํจ์๋ก์ ์ฐ์ฐ์ ์ค๋ฒ๋ก๋ฉ
์ด๋ด ๋๋ ๋น์ ํ์ ์ธ ์์๋ฅผ ํ๋ ์๊ฐํด๋ณด์ธ์! ๋ฌผ๋ก ๋
ผ๋ฆฌ์ ์ธ ๋น์ฝ์ด ๋ง์ด ์์ฌ์์ง๋ง, ๊ทธ๋๋ ์ ํํ
๋ ์ดํดํ๋๋ฐ ๋์์ด ์กฐ๊ธ ๋์ด์ ๊ฐ์ ์๋ฌธ์ ๊ฐ์ง๋ ๋ค๋ฅธ ๋ถ๋ค๊ป๋ ์์ฃผ ์กฐ๊ธ์ด๋๋ง ๋์์ด ๋๊ณ ์ ๊ธ ๋จ๊น๋๋น ์ค๋ ์ ๋
์ ๋ฐฅ๊ณผ ๋ผ์ง๊ณ ๊ธฐ๋ฅผ ๋จน๊ณ ์ถ์ด์. ๊ทผ๋ฐ ์ ๋(ํจ์๋) ์ง๊ธ ๋ฐ์(ํด๋์ค ๋ฐ์) ์์ด์ ๋ฐฅ๋ ๋ชปํ๊ณ , ๋ผ์ง๊ณ ๊ธฐ๋ ๋ฐ๋ก ์ฌ์ผํด์.#include using namespace std; class Outside { public: enum Cooking { RICE = 1, PORK, }; private: Cooking ingredient; public: Outside(const Cooking ingredient) : ingredient{ingredient} {} Outside(const int ingredient) : ingredient{Cooking(ingredient)} {} Cooking get_ingredient() const {return ingredient;} }; Outside operator + (Outside& o1, Outside& o2) { return Outside(o1.get_ingredient() + o2.get_ingredient()); } int main() { Outside rice(Outside::RICE); Outside pork(Outside::PORK); if(Outside(pork + rice).get_ingredient() == 3) cout ํด๋์ค ๋ฐ์ ์๋ ํจ์๋ ๋ผ์ง๊ณ ๊ธฐ๋ ๋ฐ๋ก ๊ตฌํ๊ณ , ๋ฐฅ๋ ๋ฐ๋ก ๊ตฌํด์ ์๋จ์ ๋ง๋ จํด์ผ ํด์. ์ ๋(ํจ์๋) ์ง ์์(ํด๋์ค ์์) ์์ด์! ๊ทธ๋์ ๋ฐฅ์ ๊ทธ๋ฅ ์ฌ๊ธฐ์ ์ง์ผ๋ฉด ๋๊ณ , ๋ผ์ง๊ณ ๊ธฐ๋ง ๊ตฌ์
ํ๋ฉด ๋ผ์!#include using namespace std; class Home { public: enum Cooking { RICE = 1, PORK, }; private: Cooking ingredient; public: Home(const Cooking ingredient) : ingredient{ingredient} {} Home(const int ingredient) : ingredient{Cooking(ingredient)} {} Cooking get_ingredient() const {return ingredient;} Home operator + (Home& o1) { return Home(this->get_ingredient() + o1.get_ingredient()); } }; int main() { Home rice(Home::RICE); Home pork(Home::PORK); if(Home(pork + rice).get_ingredient() == 3) cout ํจ์๊ฐ ํด๋์ค ์์ ์์ผ๋ฉด, ๋ฐฅ์ ๊ทธ๋ฅ ์ง ์์ ์๋๊ฑธ๋ก ๋ง๋ค๊ณ (this), ๋ผ์ง๊ณ ๊ธฐ๋ง ๋ฐ๋ก ๊ตฌํด์ ์๋จ์ผ๋ก ๋ง๋ค๋ฉด ๋ผ์! ์ง๊ธ ์ง ์์ ์๋ ์ ๋ ์ ์น๊ตฌ์์. ๋ฌผ๋ก ์นํ๊ธด ํ์ง๋ง.. ์ง์ ์๋ ์์ ํจ๋ถ๋ก ๋ค์ ๊ฑฐ๋ฆฌ๋๊ฑด ์์๊ฐ ์๋๊ฒ ์ฃ ? ์น๊ตฌ๊ฐ ๋ ๋ค ์ฌ์จ๋์! #include using namespace std; class Outside { public: enum Cooking { RICE = 1, PORK, }; private: Cooking ingredient; public: Outside(const Cooking ingredient) : ingredient{ingredient} {} Outside(const int ingredient) : ingredient{Cooking(ingredient)} {} Cooking get_ingredient() const {return ingredient;} friend Outside operator + (Outside& o1, Outside& o2) { return Outside(o1.get_ingredient() + o2.get_ingredient()); } }; int main() { Outside rice(Outside::RICE); Outside pork(Outside::PORK); if(Outside(pork + rice).get_ingredient() == 3) cout ๋น๋ก ์ง ์์ ์์ง๋ง, ์น๊ตฌ์ด๊ธฐ ๋๋ฌธ์ ์ง ์์ ์ฌ๋ฃ๋ฅผ ์ง์ ์ฐธ๊ณ ํ ์ ์๊ณ , ์๊ณผ ๋ผ์ง๊ณ ๊ธฐ๋ฅผ ์ง์ ๊ตฌํด์์ผ ํด์.