tags:

views:

39

answers:

3

I have this snippet of the code

account.cpp

#include "account.h"
#include <iostream>
#include <string>  

using namespace std;

Account::Account(string firstName, string lastName, int id)
    : strFirstName(firstName), strLastName(lastName), nID(id) {}

void Account::printAccount(){
    cout << strFirstName;
}

account.h

#include <string>

using std::string;

class Account{
private:
    string strLastName;      //Client's last name
    string strFirstName;     //Client's first name
    int nID;                //Client's ID number
    int nLines;             //Number of lines related to account
    double lastBill;
public:
    Account(string firstName, string lastName, int id);
        void printAccount();
};

company.h

#ifndef CELLULAR_COMPANY_H
#define CELLULAR_COMPANY_H

#include <string>
#include <list>
#include <iostream>
#include "account.h"

using namespace std;

class Company {
private:
    list<Account> listOfAccounts;
public:
    void addAccount(string firstName, string lastName, int id) {
        Account newAccount(firstName, lastName, id);
        listOfAccounts.push_back(newAccount);
    }

    void printAccounts(){
        for(list<Account>::iterator i = listOfAccounts.begin(); i != listOfAccounts.end(); ++i){
            i.printAccount;           //here bug
        }
    }
};


#endif // CELLULAR_COMPANY_H

main.cpp

#include "cellularcompany.h"

int main(){
    Company newCompany;
    newCompany.addAccount("Pavel", "Nedved", 11111);
    newCompany.printAccounts();

    return 0;
}

can somebody please explain what does my error mean? thanks in advance (I have it in company.h see comment there) I have bug 'struct std::_List_iterator<Account>' has no member named 'printAccount'

+4  A: 

You forgot the parentheses after printAccount(). Otherwise, it's not a method call. Also, you need to use the -> operator, since it's an iterator.

for(list<Account>::iterator i = listOfAccounts.begin();
    i != listOfAccounts.end(); ++i)
{ 
    i->printAccount();  // Note the ()!
    // This is equivalent to (*i).printAccount(); 
} 
In silico
I did it now, but I have the same effect
helloWorld
thanks a lot, You are right
helloWorld
A: 

What do you mean by the comment in this line

 i.printAccount;           ****//here bug**** 

Are you testing something.

ckv
A: 

Try to change i.printAccount; to i->printAccount();

Jack Shainsky