1 Replies - 211 Views - Last Post: 11 February 2014 - 09:21 PM Rate Topic: -----

#1 Black_Epiphany  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 66
  • Joined: 02-February 14

Is it better to pass by value or reference?

Posted 11 February 2014 - 08:49 PM

I've googled this question and from what I can tell it seems that it depends on the compiler being used. I wanted to get some other opinions because I still don't know in what situations I should pass a variable by reference or not.

Thanks in advance
Is This A Good Question/Topic? 0
  • +

Replies To: Is it better to pass by value or reference?

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4140
  • View blog
  • Posts: 12,883
  • Joined: 25-December 09

Re: Is it better to pass by value or reference?

Posted 11 February 2014 - 09:21 PM

Basically you pass a variable by reference when you want to be able to change the variable in the function, you pass by value when you don't. But when dealing with classes, you would normally pass by const reference when you don't want to change the class in the function, to avoid copying the class.

You may want to study the excellent function tutorials that are contained in my signature for more information.

Jim
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1