[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppVclGraphics » sourcecode » VisualCSharp » STL » Notepad » BeginnersGuideToVB » BeginnersGuideToCSharp » CReturn » Allegro » QbasicFAQ_WhereDoIFindIt » CppProtected

(C++) protected

Keyword indicating the level of class access.

The protected member variables and functions of a class can only be used from within a derived class. From outside the class, protected members are not accessable.

The code below shows class access:
class  Base
{
  public:
    int mBasePublic;
  protected:
    int mBaseProtected;
  private:
    int mBasePrivate;
};
//The class Derived inherits publicly from class Base
//In this example, however, the type of inheritance does not matter:
//Base's protected members get accessable in this class in all cases
class Derived : public Base 
{
  public:
    int mDerivedPublicPublic;
  protected:
    int mDerivedPublicProtected;
  private:
    int mDerivedPublicPrivate;
    void testBaseAccess() const
    {
      //BasePublic is accessable from inside any derived class
      this->mBasePublic;
      //BaseProtected gets accessable from inside any derived class
      this->mBaseProtected; 
    }
};


'protected' links



last edited (November 16, 2006) by bilderbikkel, Number of views: 6361, Current Rev: 7 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Site Management by Lars Hagelin at Kontantkort.se.