Namespaces
Variants
Views
Actions

Class declaration

From cppreference.com
< cpp‎ | language
Revision as of 15:33, 7 March 2012 by Bazzy (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:cpp/language/sidebar

Contents

Syntax

Template:cpp Template:sparam { Template:sparam } Template:sparam ; (1)
Template:cpp Template:sparam : Template:sparam { Template:sparam } Template:sparam ; (2)
Template:cpp Template:sparam ; (3)
Template:cpp Template:sparam Template:cpp Template:sparam (4) (since C++11)

Class Body

A list of member and friend declarations and access specifiers:

Template:cpp (1)
Template:cpp (2)
Template:cpp (3)
Template:cpp Template:sparam (4)
Template:sparam (5)
Template:cpp Template:sparam (6)
Template:sparam (7)

Ancestor List

A list of classes that have already bee fully defined optionally prefixed with an access pecifier

Object List

An optional list of instances of the previously defined class

Explanation

  1. Defines a class and its member
  2. Defines a class inheriting other classes
  3. Forwards declares a class
  4. Defines a class that cannot be derived from ( see final )

If friend or member functions have their body defined inside the class body, they are implicitly inlined

Notes

(since C++11) A default value can be assigned to data members inside the class body (ie: not necessarily in a constructor)

See also


Example

Template:source cpp