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)
|