mardi 10 octobre 2017

How to set and call private data members of multiple classes?

Overview: I'm trying to create a bank account program that has multiple classes (4 to be exact). Here's the heirarchy -

Bank

Account accounts;

Account

Depositor depositor_info;

Int Account_number;

Double account_balance;

Depositor

Name depositor_name;

string Social Security Number;

Name

String first, last;

I can set the depositor's name, and then assign depositor to an account. However I can't seem to print out the depositor's name. Here's the main testing code:

Account test[MAX_ACCTS];

string first = "john", last = "doe", social = "132456789";
int acctNumber = 987654;
Name name;
Depositor depositor;

name.setFirst(first); // works
name.setLast(last); // works

depositor.setName(name);  // this works
depositor.setSSN(social); // this works

test[1].setDepositor(depositor); // this also works. 

cout << test[1].getDepositor(); // Here I get an error:
no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'Depositor')

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire