question about classes????

Started by
1 comment, last by graveyard filla 20 years, 3 months ago
high, i have a question, why do we sometimes send an object to a function? i know its to get access to that objects variables and inner functions, but couldnt we have access to them anyway? do you only send the object when you want to change the value of that objects variables? what about inner functions? is there any reason to send the object if your just using its functions? when do you have to send it and when can you just use it? thanks for any help.
FTA, my 2D futuristic action MMORPG
Advertisement
To talk to an object (instance ), you have to know about it. So if I want to call its methods, then I have to have access, which can be acheived in a variety of ways:

- the object is a global instance.
- (better than the above, generally) There is a static method in the class which lets you access the instance (Singleton pattern).
- You create the object yourself and thus own it.
- The object is a member of this , in a method (doesn''t work in a normal function in C++, since there is no this there)
- The object is passed in as a parameter.
You do it so you can act on the object within that function - access its attributes (data) and call its methods.



"Dear MacGuyver, here is a paper clip, a rubber band and a straw - please save my dog."
"16 days?? that's almost two weeks!!" Tucker

This topic is closed to new replies.

Advertisement