TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: MIKE WALKER
from: DARIN MCBRIDE
date: 1998-04-07 07:50:00
subject: Private / Protected

 MW> Something that I am not quite clear on is the 
 MW> difference between private and protected specifiers 
 MW> within a class. Can someone explain the difference 
 MW> between these? Also when would each be used? 
Private does not allow anyone to use that function/variable except that 
class.  Protected is the same except that derived classes have access, too.
class base
{
private:   int mine;
protected: int ours;
public:    int everyones;
};
class derived : public base
{
  void foo()
  {
    mine      = 1; // invalid - no access
    ours      = 2; // valid - have acess
    everyones = 3; // valid - have access
  }
};
void bar(base& b)
{
  b.mine      = 4; // invalid - no access
  b.ours      = 5; // invalid - no access
  b.everyones = 6; // valid - have access
}
Hope this helps,
---
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.