c_plus_plus_language_classes

C++ Classes

https://en.cppreference.com/w/cpp/language/classes

A class is a user-defined type.

A class type is defined by class-specifier, which appears in

of the

syntax. The class specifier has the following syntax:

}}

}}

| one of

,

,

}}

|

optional sequence of any number of

}}

| the name of the class that's being defined. Optionally prepended by

(sequence of names and scope-resolution operators, ending with scope-resolution operator), optionally followed by keyword

. The name may be omitted, in which case the class is unnamed (note that unnamed class cannot be final) }}

| list of one or more parent classes and the model of inheritance used for each (see

) }}

| list of access specifiers, member object and member function declarations and definitions (see

)}}

The class keys

and

are indistinguishable in C++, except that the default

and default

are

if class declaration uses the

and

if the class declaration uses the

. Both

and

can be used in a

.

The use of the class key

results in a

, which defines a class that holds only one of its data members at a time.

A class can have the following kinds of members: @1@ data members: :@a@

, including

. :@b@

@2@ member functions: :@a@

:@b@

@3@ nested types: :@a@

and

defined within the class definition :@b@ aliases of existing types, defined with

}}declarations :@c@ the name of the class within its own definition acts as a public member type alias of itself for the purpose of

(except when used to name a

): this is known as

@4@

from all unscoped enumerations defined within the class

s or

s}} @5@

(

class templates or function templates) may appear in the body of any non-local class/struct/union.

All members are defined at once in the class definition, they cannot be added to an already-defined class (unlike the members of namespaces)

A member of a class

cannot use

as its name if the member is a static data member, a member function, a member type, a member template

, an enumerator of an unscoped enumeration, a member of a member anonymous union. However, a non-static data member may use the name

as long as there are no user-declared constructors.

A class with at least one declared or inherited

member function is polymorphic. Objects of this type are

and have runtime type information stored as part of the object representation, which may be queried with

and

. Virtual member functions participate in dynamic binding.

A class with at least one declared or inherited pure virtual member function is an

. Objects of this type cannot be created.

constructor is a

: objects of this type can be manipulated by

functions at compile time. }}

Some member functions are special: under certain circumstances they are defined by the compiler even if not defined by the user. They are:

}}

}}

c_plus_plus_language_classes.txt · Last modified: 2024/05/01 04:23 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki