저는 C++을 처음 사용합니다. 나는 은행 계좌를 만들고 싶다. 첫 번째로 만든 은행 계좌에 계좌 번호 100000, 두 번째 계좌에는 100001, 세 번째 계좌에는 100002가 있어야합니다. 프로그램을 작성했지만 "숫자"의 값은 변경되지 않습니다. 모든 은행 계좌 번호는 100000입니다. 문제를 해결하는 방법을 모르겠습니다.생성 된 각 개체의 생성자에서 클래스 변수를 변경하십시오.
.H-파일
#include <iostream>
#include <string>
using namespace std;
#ifndef _ACCOUNT_H
#define _ACCOUNT_H
class account
{
private:
string name;
int accNumber;
int number= 100000;
double balance;
double limit;
public:
void setLimit(double limit);
void deposit(double amount);
bool withdraw(double amount);
void printBalance();
account(string name);
account(string name, double limit);
};
통화 당 - 파일
#include <iostream>
#include <string>
#include "account.h"
using namespace std;
account::account(string name) {
this->name= name;
accNumber= number;
number++;
balance= 0;
limit = 0;
}
account::account(string name, double amount) {
this->name= name;
accNumber = number;
number++;
balance= 0;
limit = amount;
}
void account::setLimit(double limit) {
this->limit = limit;
}
.
.
.
.
.
넌 [예약 식별자]를 사용하는 (http://stackoverflow.com/questions/
아
:
이
은 일례이며 228783/what-are-the-the-the-that-using-an-ac-identifier (역자 주)). 어쨌든, 나는 개인적으로 또는 품질에 대해 말할 수는 없지만 다음 정보가 있습니다. http://www.cprogramming.com/tutorial/statickeyword.html – chris