프로그래밍/C++
[C++] 객체 생성과 사용 예제
HSDY
2023. 2. 2. 12:18
반응형
코드
#include <iostream>
#include<string>
using namespace std;
class Point
{
public:
Point();
int x, y;
void print()
{
cout << "(" << x << "," << y << ")\n";
}
};
Point::Point() //생성자
{
x = 0;
y = 0;
}
void main()
{
Point p1, p2;
p1.x = 100;
p1.y = 100;
p1.print();
p2.x = 200;
p2.y = 200;
p2.print();
}
결과