![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
Accessor Funcs.
Could someone explain acessor funcitions for classes?
I really need some help here thanks
__________________
And there was much rejoicing... Yay.... |
|
|
|
|
|
#2 |
|
Newbie
Join Date: Mar 2005
Posts: 4
Rep Power: 0
![]() |
Explanation of C++ Accessor Methods
Hey. I can help you; glad to be of assistance.
Accessor methods are part of object oriented programming, and are part of the interface that your class uses to communicate with the outside world, the outside world being, as a possibility, your main() function. There are three parts to every class: protections (usually involving a private section and a public section), data members, and data methods. Private data members are simply variables that happen to reside within the private section of your class, and cannot be accessed by a function that is not "owned" by your object. Private data methods are simply functions that also reside within the private section of your class, and the same holds true. Public data members and methods reside within the public section of your class and are able to be accessed anywhere in your program. It's pretty clear what a public or private data member is (a variable like an int, char, or double), but an example of an accessor method whether public or private might make things clearer: Here is a definition of a very concrete, easy to understand C++ object, which contains a single accessor method: class Number { private: int n; public: // MultiplyInteger is our accessor method int MultiplyInteger ( int p ) { n *= p; } }; This is a very simple class, as you can see, but it demonstrates the concept. I'll leave you to play around with the code as it is pretty self explanatory. Accessor methods aren't all that hard if you just remember that they are REGULAR FUNCTIONS wrapped up inside a C++ class framework. That's it. Hope it helped. |
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
lol, i use them all the time never knew what they were called though.
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
Thanks a bunch..even though I don't know really how to use pointers that much either. But thanks all the same.
__________________
And there was much rejoicing... Yay.... |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|