我是新来的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);
};
的.cpp - 文件
#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 /什么-是最规则约-使用-AN-下划线在-AC-标识符)。无论如何,我无法亲自代言或反对质量,但是这有以下信息:http://www.cprogramming.com/tutorial/statickeyword.html – chris