하.. 내가 계좌 돈 보내고 받는거 만들고있는데... A놈한테서 돈이 차감됬는데 정작 B놈은 돈을 못받어 후
뭐가 잘못된거여...?
#include <iostream>
#include <string>
using namespace std;
class BankAccount {
private:
int money;
public :
string name;
BankAccount(){
money = 0;
cout << "계좌 생성"<<endl;
}
int transfer(int amount, BankAccount otherAccount);
void show(){
cout << name <<"님의 계좌 잔액은 "<< money << "원 입니다."<<endl;
}
void get(int amount);
};
int BankAccount::transfer(int amount, BankAccount otherAccount)
{
money -= amount;
otherAccount.get(amount);
cout << otherAccount.name << "님 계좌로 "<<amount<<"원 만큼 전송"<<endl;
return amount;
};
void BankAccount::get(int amount){
money += amount;
};
int main(){
BankAccount A; A.name = "에이";
BankAccount B; B.name = "비";
cout<< A.transfer(5000,B) << "원 전송완료"<<endl;
A.show();
B.show();
return 0;
}
은행이 빼돌린거임
포인터로 날리던가 레퍼런스로 날려라 인자도 사실 메모리 재할당하는거니까 니가 생각하는 B한테 값이 전달되는게아니라 새로 생성된 백어카운트 클래스의 복사생성자가 호출되서 날라가는거야