굳이 C++ 에서 struct 쓸이유있나여?
// 화투 한장을 표현하는 클래스
struct SCard
{
char Name[4];
SCard() { Name[0]=0; }
SCard(const char *pName) {
strcpy(Name,pName);
}
int GetNumber() const {
if (isdigit(Name[0])) return Name[0]-'0';
if (Name[0]=='J') return 10;
if (Name[0]=='D') return 11;
return 12;
};
int GetKind() const {
if (strcmp(Name+1,"광")==0) return 0;
else if (strcmp(Name+1,"십")==0) return 1;
else if (strcmp(Name+1,"오")==0) return 2;
else return 3;
}
friend ostream &operator <<(ostream &c, const SCard &C) {
return c << C.Name;
}
bool operator ==(const SCard &Other) const {
return (strcmp(Name,Other.Name) == 0);
}
bool operator <(const SCard &Other) const {
if (GetNumber() < Other.GetNumber()) return true;
if (GetNumber() > Other.GetNumber()) return false;
if (GetKind() < Other.GetKind()) return true;
return false;
}
};
그러게여
C++에서 class는 기본적으로 멤버 참조시 private이고
struct는 public인거 이외에는 차이가 없는데
일반적으로 메소드가 없는 단순히 데이터를 담는 형태로써 쓸 때 struct를 많이 써용
객체지향 개념인 추상화, 정보은닉을 구현하기 위해서?