Я создаю проект, в котором я показываю банковский счет. Я создал класс Account и класс Person - Account имеет баланс, номер учетной записи и объект Person, у которого есть имя и адрес. Я сохранил три объекта Account в векторе, но не могу понять, как напечатать Person (а именно имя и адрес). Вот некоторые фрагменты моего кода внутри моего драйвера:Печать объекта внутри объекта в векторе C++
#include <iostream>
#include <string>
#include <vector>
#include "Account.h"
#include "Person.h"
using namespace std;
// Creates Person object Drew with name "Drew" address "60 N Main"
Person Drew("Drew", "60 N Main");
// Create Account DrewAccount with account number 1, using Person Drew,
// and setting balance to 500.00
Account DrewAccount(1, Drew, 500.00);
// This is inside my printAccount function
int size = accountVec.size();
for (unsigned int index = 0; index < size; index++)
{
cout << accountVec[index].getAccountNum();
// This accountHolder is the Person object Drew and is giving me issues
// Gives Error:no operator "<<" matches these operands
// operand types are: std::ostream << Person
cout << accountVec[index].getAccountHolder();
cout << accountVec[index].getAccountBal();
}
Что мне не хватает?
Я подозреваю getAccountHolder() является фактическим объектом возвращается, и вы не переопределять оператор <<. Можете ли вы показать определения классов? – PDizzle745
Добавьте оператор перегрузки '<<' в класс 'Person' и используйте' cout << (Some person) << endl; '. См. [Перегрузка оператора] (http://en.cppreference.com/w/cpp/language/operators) – pwwpche
Также я не вижу, где заполняется вектор? – PDizzle745