|
-
March 26th, 2008, 06:41 AM
#8
Re: pointers....
 Originally Posted by armen_shlang
Ok I'm sorry but the answers didn't digest quite well. Even though I'm sure an average person would've got it by now, but I didn't.
Code:
string& getCompanyName() {return companyName;};
string& getTitle() {return title;};
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.
By returning a string, that string can last beyond the life the object.
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|