/* 4. ´ÙÀ½ ÇÁ·Î±×·¥ÀÇ Ãâ·ÂÀ» ½á¶ó. */ #include #include int number[5] = { 1, 2, 3, 4, 5 }; class Test { int x; int *y; public: Test() { x = 0; y = &x; } void add(int p) { x = x + p; *y = *y + p; } int& getX() { return x; } int getY() { return *y; } void setX(int p) { x = p; }; void setY(int p) { *y = p; }; }; void main() { Test sample; sample.setX(number[0]); sample.setY(number[1]); sample.add(number[2]); int& a = sample.getX(); a = number[3]; int b = sample.getY(); b = number[4]; printf("x = %d, y = %d\n", sample.getX(), sample.getY()); }