Skip to main content
gamedev.net
🔒 Locked

C/C++ Object Parameter Passing

Started by LostSource Apr 12, 2006 at 2:18 AM 2 replies 400+ views
Original Post
LostSource
LostSource
Lang: C/C++ I was just curious about what is the best way to pass parameters of an object. For example say we have a function foo and we are wanting to pass an object (any object that comes to your mind while reading this) into function foo. For example:

    ___ namespace of object
    |      ________________ the object
    |      |       ____________________  the name of the object
    |      |       |
Foo(obj::Object object); 
What would be the best way to pass this object in this situtations: [1] the object won't experience any change [2] the object will experience some change All relpies are appreciated! = ] Ps: How do you add links in one's signature?
Zakwayda
Zakwayda
Can't say what the 'best' way is, but generally:
Quote:
[1] the object won't experience any change
By value for built-in types, constant reference for others.
Quote:
[2] the object will experience some change
Non-constant reference.
Rebooted
Rebooted
Quote:
Original post by LostSource
[2] the object will experience some change

If the change only happens inside the function, then by value.

If the change is visible to the caller once the function returns, then by non constant reference.
Aardvajk
Aardvajk
http://www.gamedev.net/community/forums/topic.asp?topic_id=383862

has a fairly in-depth discussion of this.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.