πŸ’» Dev & CSC++ Programming

C++ Programming Ch.10 Exercise 7 Solution

Problem: λ‹€μŒ ν”„λ‘œκ·Έλž¨μ€ 컴파일 였λ₯˜κ°€ λ°œμƒν•œλ‹€. μ†ŒμŠ€μ˜ μ–΄λ””μ—μ„œ μ™œ 컴파일 였λ₯˜κ°€ λ°œμƒν•˜λŠ”κ°€? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #include using namespace std; class Circle { int radius; public: Circle(int radius = 1) { this->radius = radius; } int getRadius() { return radius; } }; template T bigger(T a, T b) { // 두 개의 맀개 λ³€μˆ˜λ₯Ό λΉ„κ΅ν•˜μ—¬ 큰 값을 리턴 if (a > b) return a; else return b; } int main() { int a = 20, b = 50, c; c = bigger(a, b); cout << "20κ³Ό 50쀑 큰 값은 " << c << endl; Circle waffle(10), pizza(20), y; y = bigger(waffle, pizza); cout << "waffleκ³Ό pizza 쀑 큰 κ²ƒμ˜ λ°˜μ§€λ¦„μ€ " << y.getRadius() << endl; } Execution Result: ...

March 9, 2020 Β· 2 min Β· Sobamemil