열혈 c++ 프로그래밍을 보고 요약정리합니다.
class Boy
{
private:
int height;
friend class Girl;
public:
Boy(int len) : height(len)
{}
.....
};
class Girl
{
private:
char phNum[20];
public:
Girl(char *num)
{
strcpy(phNum, num);
}
void ShowYourFriendInfo(Boy &frn)
{
cout << "His height: " << frn.height << endl;
}
};
이 변수는 객체 외부에 있지만 객체에게 멤버변수처럼 접근할 수 있는 권한이 있는것
static 멤버 변수의 초기화 방법
int SoSimple::simObjCnt = 0;
멤버 변수 선언과 동시에 값을 초기화하는게 더 낫지 않을까 했는데 그렇게는 허용이 안된다.
static int simObjCnt = 0;
const static int RUSSIA = 1707540;
CountryArea::RUCCIA;
class Account{
private:
int id;
int balance;
char *name;
Account(int id, int balance, char *name) {
this->id = id;
this->balance = balance;
this->name = new char[::strlen(name) + 1];
::strcpy(this->name, name);
}
public:
Account() {
}
Account(const Account & account)
{
this->id = account.id;
this->balance = account.balance;
this->name = new char[strlen(account.name) + 1];
strcpy(this->name, account.name);
}
static Account Of(int _id, int _balance, char* _name) {
return Account(_id, _balance, _name);
}
bool IsSame(int id) {
return this->id == id;
}
void Deposit(int money) {
this->balance += money;
}
void Withdraw(int money) {
if (this->balance < money) {
cout << "잔액부족\n";
return;
}
this->balance -= money;
cout << "출금완료\n";
}
void ShowInfo() const {
cout << "계좌ID: " << id << "\n";
cout << "이 름: " << name << "\n";
cout << "잔 액: " << balance << "\n";
}
Account* Copy() {
return new Account(this->id, this->balance, this->name);
}
};