Quote:
Originally Posted by armen_shlang
What practical purpose would you have of returning a reference to a string? Just return the string.Code:string& getCompanyName() {return companyName;};
string& getTitle() {return title;};
What if I want to get the company name, and in some other non-related function, write that name to a file, long after the object is gone? You can't do that with the code you posted, since that reference is tied to the object.Code:string getCompanyName() {return companyName;};
string getTitle() {return title;};
By returning a string, that string can last beyond the life the object.
Regards,
Paul McKenzie
