내가 바보인데다 게을러서 이런데다 올리는거니깐 존나 까도 좋은데 답만알려주라;;


#include<iostream>

using namespace::std;

char str[100];

class Account{
   int id;
   int balance;
   char* name;

public:
   Account() {}

   Account(int id, int balance, char* name){
           this->id = id;
           this->balance = balance;
           this->name = new char[strlen(name)+1];
           strcpy(this->name, name);
        }

   ~Account(){
              delete []name;
   }

   Account(const Account& acc){                    //복사생성자
             this->id = acc.id;
             this->balance = acc.balance;
             this->name = new char[strlen(acc.name)+1];
             strcpy(this->name, acc.name);
   }


        int getId(){
                return id;
        }

        int getBalance(){
                return balance;
        }

        char* getName(){
                return name;
        }

        void AddMoney(int money){
                this->balance += money;
        }

        void MinMoney(int money){
                this-> balance -= money;
        }

        void showAll(){
                cout << "-----------------------------------" << endl;
                cout << "ID : " << this->id << endl;
                cout << "Balance : " << this->balance << endl;
                cout << "Name : " << this->name << endl;
                cout << "-----------------------------------" << endl;
        }
};

Account* pArray[100];
int index=0;

void PrintMenu();
void MakeAccount();
void Deposit();
void Withdraw();
void Inquire();

int main(void){
        int op;

        while(true){
                PrintMenu();
                cin >> op;

                if(op == 1)
                        MakeAccount();
                else if(op == 2)
                        Deposit();
                else if(op == 3)
                        Withdraw();
                else if(op == 4)
                        Inquire();
                else
                        break;
        }

        pArray[index] = new Account(pArray[0]);

        return 0;
}

void PrintMenu(){
        cout << "=============================================" << endl;
        cout << "1. 계좌 계설" << endl;
        cout << "2. 입     금" << endl;
        cout << "3. 출     금" << endl;
        cout << "4. 전체 고객 잔액 조회" << endl;
        cout << "이외의 수를 입력하면 종료합니다.." << endl;
        cout << "=============================================" << endl;
        cout << "입력: ";
        
}

void MakeAccount(){
        int id;
        int balance;
        
        cout << "생성할 계좌의 ID: ";
        cin >> id;
        cout << "생성할 계좌의 소유주: ";
        cin >> str;
        cout << "생성할 계좌의 잔액: ";
        cin >> balance;

        pArray[index++] = new Account(id, balance, str);
}

void Deposit(){
        int id; int balance;
        
        cout << "입금할 계좌의 ID: ";
        cin >> id;

        cout << "입금할 금액: ";
        cin >> balance;

        for(int i=0 ; i<index ; i++){
                if(pArray[i]->getId() == id){
                        pArray[i]->AddMoney(balance);
                        break;
                }
        }
}

void Withdraw(){
        int id;
        int balance;

        cout << "출금할 계좌의 ID: ";
        cin >> id;

        cout << "출금할 금액: ";
        cin >> balance;

        for(int i=0 ; i<index ; i++){
                if(pArray[i]->getId() == id){
                        if(pArray[i]->getBalance() < balance){
                                cout << "잔액부족!" << endl;
                                break;
                        }
                        else{
                                pArray[i]->MinMoney(balance);
                                cout << "출금성공!" << endl;
                        }
                                
                }
        }
}

void Inquire(){
        cout << "===========================================" << endl;

        for(int i=0 ; i<index ; i++)
                pArray[i]->showAll();

        cout << "===========================================" << endl;
}



반도의 흔한 기본예제인데;;

내가 궁금한게 뭐냐면

저위에 복사생성자 있잖아

복사생성자에서 Account에서 멤버변수들은 분명 private인데 어떻게 그냥 접근이 가능하지?;;

전에 복사생성자 볼때는 아무렇지 않게 넘겼는데

이제와서 타이핑해보면서 보니깐 겁나 이상한거 같아서;;

저리쳐도 왜 에러가 안나는지 모르겠어

형들 좀 도와줘 ㅠㅠ