Quantcast

Jump to content

» «
Photo

C++ Call by reference/value

2 replies to this topic
BallsOfSteel
  • BallsOfSteel

    Player Hater

  • Members
  • Joined: 30 Jan 2013

#1

Posted 30 January 2013 - 04:23 PM

GetNetworkIdFromVehicle(Vehicle vehicle, f32 *netID)
I know that the function has direct access to the object but why would I need to do that?

And this one which calls by value, making a copy of the object netid
requestControlOfNetworkId(f32 netID)

I don't understand why the object needs to be called by reference on the first function
Could someone explain me when and why I'm supposed to use them, please?

spadger
  • spadger

    Player Hater

  • Members
  • Joined: 28 Jun 2012

#2

Posted 23 March 2013 - 07:01 PM

QUOTE (BallsOfSteel @ Wednesday, Jan 30 2013, 16:23)
GetNetworkIdFromVehicle(Vehicle vehicle, f32 *netID)
I know that the function has direct access to the object but why would I need to do that?

And this one which calls by value, making a copy of the object netid
requestControlOfNetworkId(f32 netID)

I don't understand why the object needs to be called by reference on the first function
Could someone explain me when and why I'm supposed to use them, please?

They're function prototypes to tell the compiler what each funtions arguments and return values are.

The f32 *netid is a pointer, so the function will require the address of the float rather than the float variable value.

Yes the second one requires the float value ( a copy of ) as opposed to by reference with the first example.

Hope this clears up some understanding smile.gif

nixolas1
  • nixolas1

    Creator/Destroyer

  • Members
  • Joined: 23 Dec 2008
  • None

#3

Posted 25 March 2013 - 10:52 AM Edited by nixolas1, 25 March 2013 - 10:55 AM.

you should really read some c++ tutorials! smile.gif

Also, GetNetworkIdFromVehicle(Vehicle vehicle, f32 *netID) will save the netid of the vehicle you select, so it needs "direct access to the object", and requestControlOfNetworkId(f32 netID) only reads the float value, and does not need access to the pointer location or whatever.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users