Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   c++ classes (http://www.programmingforums.org/showthread.php?t=11997)

n00b Nov 25th, 2006 11:13 AM

c++ classes
 
why do methods belong to objects only logically, and not physically?

grumpy Nov 25th, 2006 11:36 AM

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.

mackenga Dec 1st, 2006 5:28 PM

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