![]() |
c++ classes
why do methods belong to objects only logically, and not physically?
|
Because methods (or member functions in C++ standardese) represent actions that are performed on (or by) an object. Static member functions represent actions that affect (eg visible to) all objects of a class.
The action of lifting your arm is something associated with you, but it is not physically part of you. Even member functions that (say) return a reference to an internal data member can be described as allowing an action on that internal data member. |
Or, an alternative answer that also seems logical: all instances of an object need their own separate copy of any non-static data members, because they may not be the same for the different instances. However, the methods will be the same for all instances, so what would be the point in physically giving each instance its own copy of the method?
|
| All times are GMT -5. The time now is 1:21 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC