LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C++ containment (https://www.linuxquestions.org/questions/programming-9/c-containment-410805/)

linuxmandrake 02-02-2006 06:06 AM

C++ containment
 
I dont quite understand why the + operator can't be called within the following statement
String buffer Edie.GetFirstName() + Edie.GetLastName();

Edie is an employee object which uses the following string class

code for + operaotor within string class

PHP Code:

String String::operator+(const String&  rhs

--the rest of the code are assignment statments which dont change rhs--

The GetFirstName returns a constant string which is what the function accepts as a parameter. The book said in order to fix this I would have to overload the GetFirstName to be non const because u cant use the + operator on a constant object which is returned by GetFirstName.

const String & GetFirstName() const

is it because u cant have a constant pointer to a constant object?

acid_kewpie 02-02-2006 06:33 AM

Please do not post the same thread in more than one forum. Picking the most relevant forum and posting it once there makes it easier for other members to help you and keeps the discussion all in one place.

http://www.linuxquestions.org/rules.php


All times are GMT -5. The time now is 03:12 PM.