05-26-2003, 07:57 PM | #1 (permalink) |
Upright
Location: Chicago, Ill
|
Any C++ programmers in the house??/
This is my homework, no i don't need it done, i only need a tip on why my overloaded operator and iterator function in public is just giving me the same(too many parameter) error. This part of the program is supposed to print all the objects in the already setup lists in the bank class... I only need a hint, not the solution(unless you are willing to do that, but i wouldn't be learning anything). Thanks.
Code:
#include <iostream> #include <list> #include <fstream> #include <string> using namespace std; class account { public: account(): n(0), d(0.0) {} account(int acct, string acctname, float abalance) : n(acct), str1(acctname), d(abalance) {} friend ostream& operator << (ostream& os, account& p) { cout << "Printing original data in the account: " << endl; for(Act = accountlist.begin(); Act != accountlist.end(); Act++) { os << *Act << " "; } cout << endl; } private: int n; string str1; float d; list<account>::iterator Act; }; class transaction { public: transaction(): n1(0), d1(0.0) {} transaction(int acctnm, string lttr, float tamount) : n1(acctnm), c(lttr), d1(tamount) {} friend ostream& operator << (ostream os, transaction& q ) { cout << "Printing original transaction data: " << endl; for(Trn = transactionlist.begin(); Trn != transactionlist.end(); Act++) { os << *Trn << ' '; } cout << endl; } private: int n1; string c; float d1; list<transaction>::iterator Trn; }; class bank { public: void openaccounts() { int n; string str1; float d; account *p; ifstream datafile("Myaccounts.txt"); { while(!datafile.eof()) { datafile >> n >> str1 >> d; p=new account(n, str1, d); accountlist.push_back(*p); } } } void opentransactions() { int n1; string c; float d1; transaction *q; ifstream datafile("Mytransactions.txt"); { while(!datafile.eof()) { datafile >> n1 >> c >> d1; q=new transaction(n1, c, d1); transactionlist.push_back(*q); } } } private: list<account>accountlist; list<transaction>transactionlist; }; int main() { bank business; business.openaccounts(); business.opentransactions(); return 0; } Last edited by cheerios; 05-27-2003 at 07:51 AM.. |
05-27-2003, 08:28 PM | #4 (permalink) |
Tilted
Location: Ontario, Canada
|
I'm pretty new to C++ (only one semester under my belt right now)... however, just curious, what are you '#include'ing? From what I can tell, that may be the problem, as it is used 4 times, but nothing is declared after. I'm thinking you're missing:
#include <iostream> #include <string> #include <fstream> #include <list> Try that out and lemme know what happens! Edit: My bad, the vbCode of this website blanks out the template declarations... weird Kinda figured you didn't forget them anyways
__________________
" Can't keep my eyes from the circling skies, Tongue-tied and twisted just an earth-bound misfit, I " Last edited by Nooze2k; 05-27-2003 at 08:30 PM.. |
Tags |
house or, programmers |
|
|