I have the following struct:
struct Transaction {
Transaction(Book& bb, Patron& pp, Date dd)
: b(bb), p(pp), d(dd) { }
Book& b;
Patron& p
Date d;
};
When I try to put an object of type Transaction into a vector<Transaction>v_t with a push_back, it won’t work. A screenful of errors breaks lose.
Is it because I have references as members of my object?
You’ll need an assignment and copy operator for the type since it contains a reference. STL container objects must be copyable AND assignable (and this won’t be possible with your reference unfortunately).
Check this thread:
http://cboard.cprogramming.com/cplusplus-programming/106779-copy-constructor-class-const-reference-member.html
It discusses the problem and some alternate solutions, though it basically says don’t have a reference member in container type.