public

C++ Specific —>

public: [member-list]

publicbase-class

When preceding a list of class members, the public keyword specifies that those members are accessible from any function. This applies to all members declared up to the next access specifier or the end of the class.

When preceding the name of a base class, the public keyword specifies that the public and protected members of the base class are public and protected members, respectively, of the derived class.

Default access of members in a class is private. Default access of members in a structure or union is public.

Default access of a base class is private for classes and public for structures. Unions cannot have base classes.

For more information, see private, protected, friend, and Table of Member Access Privileges.

END C++ Specific

Example

// Example of the public keyword
class BaseClass
{
public:
   int pubFunc();
};

class DerivedClass : public BaseClass
{
};
void main()
{
   BaseClass aBase;
   DerivedClass aDerived;
   aBase.pubFunc();       // pubFunc() is accessible
                          //    from any function
   aDerived.pubFunc();    // pubFunc() is still public in
                          //    derived class
}