<Class>
쓰는 이유?
Class member
- 클래스를 구성하는 요소
- 멤버 변수와 멤버 함수가 있음
- Ex) memeber variable : name, id
- Ex) member function : getName(), getID()
- 멤버 변수는 클래스의 상태를 나타내고, 멤버 함수는 클래스의 동작을 정의함
- 클래스 멤버들은 객체를 생성할 때마다 각자의 고유한 값을 가지게 됨
선언부(Declaration)와 구현부(Implementation)
class Student{
string name;
int id;
public :
string getName();
int getID();
};
string Student::getName(){
return name;
}
int Student::getID(){
return id;
}
Constructor(생성자)
- 객체가 만들어질 때 자동으로 호출되는 멤버함수
- 무조건 public으로 선언