May 03, 2024, 01:47:50 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Public/Private class variables/methods

Started by Bruce Peaslee, January 03, 2006, 09:13:08 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

What is the thinking on Public and Private member variables and methods?
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

C++ uses private, protected and pubic variables and methods.  It's a way of controlling access.

Public variables and methods are accessable outside of the class, such as in the 'main' subroutine or by another class that has a pointer to the class in question.

Protected variables and methods are only accessable by code in that class, or any derived class.  In other words a class method can access the variable but no other class or global function can.  The idea is there are variables you don't want accessed outside of your class.

Private variables and methods are only accessable by the base class they are defined in.  Derived classes don't have access.

Paul.
Ionic Wind Support Team

Bruce Peaslee

Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Ionic Wind Support Team

Perhaps.  Still debating on it.

It does help when your sharing code libraries and don't want users mucking about in the internals.
Ionic Wind Support Team

Parker

In my opinion, adding features can never hurt, of course it could be a low priority item. If you don't want to use them you don't have to. But if you do want that extra safety of knowing other people won't modify your classes, then you can.

Zen

Yes i think it is a good idea to have them for sharing statics, there is always someone who will encounter a problem either acciedntly or on purpose. So like Parker said, a little bit of extra safety.

So i guess i wouldnt mind this being added later on.

Lewis