![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
|
c++ classes
why do methods belong to objects only logically, and not physically?
|
|
|
|
|
|
#2 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,206
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4
![]() |
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?
__________________
"I'm not a genius. Why do I have to suffer?" |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Could some please explain classes to me... | TCStyle | C++ | 10 | Feb 20th, 2006 3:51 PM |
| What is Lightweight C++? difference in inner classes between C++ and Java? | jonyzz | C++ | 4 | Sep 2nd, 2005 9:56 AM |
| List of classes | Dark_Shinobi | C++ | 8 | May 23rd, 2005 3:50 PM |
| Classes | Sane | Python | 8 | Apr 29th, 2005 12:50 PM |
| C++ Classes - Quick question(s) | Delete | C++ | 8 | Apr 7th, 2005 7:38 PM |