次の方法で共有


Inheritance (C++)

 

The latest version of this topic can be found at Inheritance (C++).

This section explains how to use derived classes to produce extensible programs.

Overview

New classes can be derived from existing classes using a mechanism called "inheritance" (see the information beginning in Single Inheritance). Classes that are used for derivation are called "base classes" of a particular derived class. A derived class is declared using the following syntax:

 class Derived : [virtual] [access-specifier] Base  
{  
   // member list  
};  
 class Derived : [virtual] [access-specifier] Base1,  
 [virtual] [access-specifier] Base2, . . .  
{  
   // member list  
};  

After the tag (name) for the class, a colon appears followed by a list of base specifications. The base classes so named must have been declared previously. The base specifications may contain an access specifier, which is one of the keywords public, protected or private. These access specifiers appear before the base class name and apply only to that base class. These specifiers control the derived class's permission to use to members of the base class. See Member-Access Control for information on access to base class members. If the access specifier is omitted, the access to that base is considered private. The base specifications may contain the keyword virtual to indicate virtual inheritance. This keyword may appear before or after the access specifier, if any. If virtual inheritance is used, the base class is referred to as a virtual base class. For more information, see Virtual Base Classes.

Multiple base classes can be specified, separated by commas. If a single base class is specified, the inheritance model is Single inheritance.If more than one base class is specified, the inheritance model is called Multiple inheritance,

The following topics are included:

The __super and __interface keywords are documented in this section.

See Also

C++ Language Reference