반응형
보통 생성자 안에서 객체의 멤버변수를 초기화.
but 생성자는
- 초기화단계
- 몸체
두 곳에서 호출.
대부분의 변수 -> 양쪽 어느 곳에서나 설정가능.
초기화 단계에서 초기화가 깔끔.
cat::cat () :
but 생성자는
- 초기화단계
- 몸체
두 곳에서 호출.
대부분의 변수 -> 양쪽 어느 곳에서나 설정가능.
초기화 단계에서 초기화가 깔끔.
cat::cat () :
itsAge (5),
itsWeight (8)
itsWeight (8)
{ }
요렇게 구현.
class cat
요렇게 구현.
class cat
{
public:
cat (int age, int weight);
~cat () {}
int GetAge () { return itsAge; }
int GetWeight () { return itsWeight; }
~cat () {}
int GetAge () { return itsAge; }
int GetWeight () { return itsWeight; }
private:
int itsAge;
int itsWeight;
int itsWeight;
};
cat::cat (int age, int weight) :
itsAge (age), itsWeight (weight) {}
이런식으로도 구현 가능.
cat::cat (int age, int weight) :
itsAge (age), itsWeight (weight) {}
이런식으로도 구현 가능.
반응형
'Programming > C_C++' 카테고리의 다른 글
전처리기 활용 ** (0) | 2011.08.17 |
---|---|
전처리기 (0) | 2011.08.17 |
ture, false (0) | 2011.07.18 |
reference (참조자) (0) | 2011.07.14 |
c main (0) | 2011.07.14 |