function return value

a little question with return value

Page 1 of 1

2 Replies - 548 Views - Last Post: 06 November 2009 - 07:53 AM Rate Topic: -----

#1 Anarion  Icon User is offline

  • The Persian Coder
  • member icon

Reputation: 282
  • View blog
  • Posts: 1,456
  • Joined: 16-May 09

function return value

Posted 06 November 2009 - 02:10 AM

Hi, I was working with operator overloading for a class and I reached this function:
record& record::operator=(record &rec) {
		id = rec.id;
		data = rec.data;
		return *this;
}
My confusion is with the "&" in function's return value. Is this passing by reference just like in function arguments ?

Thanks :)

Is This A Good Question/Topic? 0
  • +

Replies To: function return value

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5951
  • View blog
  • Posts: 23,215
  • Joined: 23-August 08

Re: function return value

Posted 06 November 2009 - 06:39 AM

Yes, you're returning a reference to the object on which this operator was called.
Was This Post Helpful? 1
  • +
  • -

#3 noyesa  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 27
  • Joined: 01-April 09

Re: function return value

Posted 06 November 2009 - 07:53 AM

Yes, as with most object oriented programming, you're almost always dealing with references. It's explicit in C++, but note that many other programming languages (and virtually all modern ones) return references to objects by default.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1