В моем конструкторе "Portfolio" он считает, что мой отладчик думает, что я пытаюсь установить для него тип возвращаемого значения. Я не понимаю, почему.
#include <iostream>
#include <iomanip>
using namespace std;
class BankAccount
{
private:
int accountNum;
double accountBal;
double annualIntRate;
public:
BankAccount(int, double balance = 0.0, double rate = 0.0);
BankAccount();
void enterAccountData();
void computeInterest(int);
void displayAccount();
double getBalance();
};
//implementation section:
BankAccount::BankAccount()
{
accountNum = 0;
accountBal = 0;
annualIntRate = 0;
}
BankAccount::BankAccount(int account, double balance, double rate)
{
const int LOWEST = 1000;
const int HIGHEST = 9999;
if(account < LOWEST || account > HIGHEST)
{
accountNum = 0;
}
else
{
accountNum = account;
}
accountBal = balance;
annualIntRate = rate;
}
void BankAccount::enterAccountData()
{
cout << setprecision(2) << fixed;
cout << "Enter the account number " << endl;
cin >> accountNum;
while(accountNum < 1000)
{
cout << "Account numbers cannot be negative or less than 1000 " <<
"Enter a new account number: " << endl;
cin >> accountNum;
}
cout << "Enter the account balance " << endl;
cin >> accountBal;
while(accountBal < 0)
{
cout << "Account balances cannot be negative. " <<
"Enter a new account balance: " << endl;
cin >> accountBal;
}
}
void BankAccount::computeInterest(int months)
{
const int MONTHS_IN_YEAR = 12;
int years = 0;
double rate = 0;
int count = 0;
cout << endl << "How many years will account # " << accountNum << " be held for? (1 to 40 years) " << endl;
cin >> years;
months = years * 12;
count = 0;
while(years < 1 || years > 40)
{
cout << "Term must be from 1 to 40." << endl;
cin >> years;
}
do
{
accountBal = accountBal * annualIntRate + accountBal;
count++;
if(count == 12)
{
cout << endl << "The balance after " << months << " months is " << endl;
}
}while(count < months);
cout << "$" << accountBal << endl;
}
void BankAccount::displayAccount()
{
cout << "Account: " << accountNum << endl << "Balance is: " <<
accountBal << endl << "Interest rate is: " << annualIntRate;
cout << endl;
}
double BankAccount::getBalance()
{
return accountBal;
}
class Portfolio
{
private:
int clientNum;
BankAccount checkingAccount;
BankAccount savingsAccount;
double stockMarketHld;
double estateHld;
public:
Portfolio(int,int,double,int,double,double,double,double);
void balancePortfolio();
}
Portfolio::Portfolio(int client, int checkNum, double checkBal,
int savingNum, double savingBal, double savingRate, double stock, double estate)
: checkingAccount(checkNum, checkBal),
savingsAccount(savingNum, savingBal, savingRate)
{
clientNum = client;
stockMarketHld = stock;
estateHld = estate;
balancePortfolio();
}
void Portfolio::balancePortfolio()
{
cout << "This works, yay ^_^" << endl;
}
int main()
{
BankAccount bankAcct1(3452);
BankAccount bankAcct2(4325, 0, 0.53);
BankAccount bankAcct3(1113, 58392, 0.25);
BankAccount bankAcct4(4444, 86);
bankAcct1.displayAccount();
bankAcct2.displayAccount();
bankAcct3.displayAccount();
bankAcct4.displayAccount();
system("pause");
return 0;
}
Это происходит здесь, если я уберу "двойной запас и двойное имущество", это работает ....
Portfolio::Portfolio(int client, int checkNum, double checkBal,
int savingNum, double savingBal, double savingRate, double stock, double estate)
: checkingAccount(checkNum, checkBal),
savingsAccount(savingNum, savingBal, savingRate)
{
Кто-нибудь может пролить свет на некоторые вещи для меня?