C++ 非静态数据成员初始值设定项仅适用于-std=c++;11或-std=gnu++;11
C++ 非静态数据成员初始值设定项仅适用于-std=c++;11或-std=gnu++;11,c++,C++,[警告]非静态数据成员初始值设定项仅适用于-std=c++11或-std=gnu++11 下面我使用了/来显示我得到错误的三行代码,尽管代码运行良好 #include <iostream> #include <conio.h> using namespace std; class Bank { private: char name[20]; int accNo; char x; double balance; double
[警告]非静态数据成员初始值设定项仅适用于-std=c++11或-std=gnu++11
下面我使用了/
来显示我得到错误的三行代码,尽管代码运行良好
#include <iostream>
#include <conio.h>
using namespace std;
class Bank
{
private:
char name[20];
int accNo;
char x;
double balance;
double amount;
float interestRate;
float servCharge = 5; //[Warning]
float count = 0; //[Warning]
bool status = true; //[Warning]
public:
void openAccount();
void depositMoney();
void withdrawMoney();
void checkBalance_info();
void calcInt();
void monthlyProc();
};
void Bank::calcInt() {
cout << " Enter your annual interestRate : " << endl;
cin >> interestRate;
double monthlyInterestRate = interestRate / 12;
double monthlyInterest = balance * monthlyInterestRate;
balance += monthlyInterest;
cout << "Updated Balance After Monthly interestRate " << balance << endl;
if (balance < 25){
status = true;
}
void Bank :: monthlyProc(){
if (balance < 25){
status = false;
}
while (count > 4){
balance = balance - 1;
}
servCharge = servCharge + (count * 0.10);
balance -= servCharge;
cout << "Monthly Service Charges: " << servCharge <<endl;
cout << "Updated Balance After Monthly interestRate " << balance << endl;
}
#包括
#包括
使用名称空间std;
班级银行
{
私人:
字符名[20];
国际会计准则;
字符x;
双平衡;
双倍金额;
浮动酯;
浮动服务费用=5;//[警告]
浮动计数=0;//[警告]
bool status=true;//[警告]
公众:
作废openAccount();
无效存款();
使金钱无效();
作废支票余额信息();
空心煅烧炉();
void monthlyProc();
};
空库::煅烧炉(){
不能进行酯交换;
双月利率=利率/12;
双月利息=余额*月利息;
余额+=月利息;
库特
这些是警告,而不是错误。这意味着您正在初始化类中的那些成员变量,但它们不是静态成员。这是旧的C++98和C++03的限制
您可以通过两种方式消除这些警告:
(1) 执行编译器希望您执行的操作,即在编译代码时指定以下选项:
-std=c++11 or -std=gnu++11 // using newer C++11
(2) 在类定义中初始化它们,而不是使用旧方法初始化它们,即使用构造函数:
Bank::Bank() : servCharge(5), count(0), status(true)
{
//..
}
仅在C++11之后才受支持。换句话说,代码将无法在C++03或C++98模式下编译。要消除警告,您需要告诉编译器您打算使用C++11语言标准,可能需要添加适用的-std
开关。作为提示和将来的参考,请缩进代码以提高可读性easons…我用良好的缩进实践编辑了您的代码,以提供有助于使其可读的代码结构,这一点非常重要,尤其是当其他人阅读、审阅或编辑您的代码时。
Bank::Bank() : servCharge(5), count(0), status(true)
{
//..
}