C++ Programming Ch.5 Exercise 10 Solution
Problem: ์ฐธ์กฐ๋ฅผ ๋ฆฌํดํ๋ ์ฝ๋๋ฅผ ์์ฑํด๋ณด์. ๋ค์ ์ฝ๋์ Execution Result๋ฅผ ์ฐธ๊ณ ํ์ฌ append() ํจ์๋ฅผ ์์ฑํ๊ณ ์ ์ฒด ํ๋ก๊ทธ๋จ์ ์์ฑํ๋ผ. append()๋ Buffer ๊ฐ์ฒด์ ๋ฌธ์์ด์ ์ถ๊ฐํ๊ณ Buffer ๊ฐ์ฒด์ ๋ํ ์ฐธ์กฐ๋ฅผ ๋ฐํํ๋ ํจ์์ด๋ค. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 class Buffer{ string text; public: Buffer(string text) { this->text = text; } void add(string next) { text += next; } // text์ next ๋ฌธ์์ด ๋ง๋ถ์ด๊ธฐ void print() { cout << text << endl; } }; int main() { Buffer buf("Hello"); Buffer& temp = append(buf, "Guys"); // buf์ ๋ฌธ์์ด์ "Guys" ๋ง๋ถ์ temp.print(); // "HelloGuys" ์ถ๋ ฅ buf.print(); // "HelloGuys" ์ถ๋ ฅ } Execution Result: ...