New issue on the same subject, so I'm putting it here.
1 2 3 4 5 6 7 8 9
friend std::ostream& operator<<(std::ostream& s, const Account& h)
{
s << "Login: " << h.getUser() << std::endl; //apparently this is trying to convert a const instance to a reference
s << "Directory: " << h.getHome() << std::endl; //same with the other three
s << "Shell: " << h.getShell() << std::endl;
s << "Gecos: " << h.getGecos() << std::endl;
return s;
}
Why are the member and non-member overloaded operators returning void?! There's a lot wrong with this code: insert and append is totally incorrect, I don't know where to start the correction. For example, every call to append moves the existing elements without freeing up the old one, you then point
In answer to your question, @Sh0es, we probably need to see at least the details for your Account class. However, I can guess what is going on.
You are passing a const reference of your class. This means it is immutable, so you are not allowed to change it in any way. Most likely, your 'get' functions have not been made immutable, so you will need to change them. Here is what it should look like
1 2 3 4 5 6 7 8 9 10 11 12 13
class Account {
public:
std::string getUser() const { // note the const
returnthis->_user;
}
// same for your other 'get' functions
// ...
private:
std::string _user;
// ...
};