Reputation: 23
[Warning] non-static data member initializers only available with -std=c++11 or -std=gnu++11
Below I have used //
to show that three lines of code where I got the error, despite the code working fine.
#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;
}
Also, I did not include the whole code cause it is a bit longer. Please tell me if I need to upload the whole code. Just need help to make the code run without any sort of error.
Upvotes: 2
Views: 1545
Reputation: 17713
float servCharge = 5; //[Warning]
float count = 0;//[Warning]
bool status = true;//[Warning]
Those are warnings, not errors. It means that you are initialising those member variables in-class but those are not static members. This was a limitation of older C++98 and C++03.
You may eliminate those warnings in two ways:
(1) Do exactly what the compiler wants you to do, ie specifying these option when compiling your code:
-std=c++11 or -std=gnu++11 // using newer C++11
(2) Do initialise those in-class definition, instead using initialising them using the old way ie. using the constructor:
Bank::Bank() : servCharge(5), count(0), status(true)
{
//..
}
Upvotes: 3