I have a Person class which has a vector of Accounts. The account class is an abstract class and has a class type CurrentAccount. I have a method which will print out a Person account details called 'printAllAccounts'. But I see to be getting an error where it says 'accounts' and it says 'expression must have a class type'. Here is the person header class: Person.h
#include "pch.h"
#include "Account.h"
using namespace std;
class Person {
public:
Person(string);
void addAccount(Account &);
bool closeAccount(int *);
void printAllAccounts();
bool creditMoney(int *, double *);
bool debitMoney(int *, double *);
virtual ~Person();
private:
const string name;
vector<Account> accounts;
};
Here is the method for for Person.cpp:
void Person::printAllAccounts()
{
if (accounts.size() > 0) {
for (int i = 0; i < accounts.size(); i++)
{
//below line of accounts is where error is happening
cout << **accounts**.at(i).printDetails().c_str() << endl;
}
}
else {
cout << "Person : " << name << " has no accounts" << endl;
}
}
[Edit] Here is print details in the Account Class:
Actually there is an error on return toRet;
Account.cpp file
void Account::printDetails() const
{
ostringstream conAcc, conBal;
conAcc << this->accountNo;
string toRet;
toRet += "Account No: ";
toRet += conAcc.str();
toRet += " Balance : ";
conBal << this->balance;
toRet += conBal.str();
return toRet;
}
Here is the Account.h header file(abstract class)
#include "pch.h"
using namespace std;
class Account {
public:
Account(int *, double *);
virtual ~Account();
bool debit(double *);
bool credit(double *);
int getAccNo();
//making it abstract
virtual double getBalance() const = 0;
virtual void printDetails() const;
private:
double balance;
int accountNo;
};