LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 02-02-2006, 06:06 AM   #1
linuxmandrake
Member
 
Registered: Sep 2004
Distribution: debian sarge 64bit (AMD)
Posts: 709

Rep: Reputation: 30
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?

Last edited by linuxmandrake; 02-02-2006 at 06:14 AM.
 
Old 02-02-2006, 06:33 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ containment linuxmandrake Programming 3 02-02-2006 02:30 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration