class keyword | Declares a class or template parameter, or elaborates a type name |
class-specifier ::= class-head { [member-specification] } class-head ::= class-key [identifier] [base-clause] | class-key nested-name :: identifier [base-clause] | class-key [nested-name ::] template-id [base-clause] class-key ::= class | struct | union member-specification ::= member-decl [member-specification] | access-specifier : [member-specification] member-decl ::= [decl-specifier-seq] [member-declarator-list] ; | function-definition [;] | qualified-id ; | using-decl | template-decl member-declarator-list ::= member-declarator | member-declarator-list , member-declarator member-declarator ::= declarator [= 0] | declarator [= constant-expression] | [identifier] : constant-expression base-clause ::= : base-specifier-list base-specifier-list ::= base-specifier | base-specifier-list , base-specifier base-specifier ::= [base-modifiers] [::] [nested-name ::] class-name base-modifiers ::= virtual [access-specifier] | access-specifier [virtual] access-specifier ::= private | protected | public class-name ::= identifier | template-id type-parm := class [identifier] [= type-id] | template < template-parm-list > class [identifier] [= id-expression] elaborated-type-specifier := class-key [::] [nested-name ::] identifier | class-key [::] [nested-name ::] [template] template-id |
The class keyword introduces a class declaration or definition, names a type template parameter (type-parm), or names a class type in an elaborated-type-specifier. In a class definition, the only difference between class and struct is that the default access level is private for class and public for struct.
When declaring a type template parameter, typename and class are interchangeable.
template<class T> // Can use typename instead of class class point { public: point(T x = 0, T y = 0); private: T x_, y_; }; point<int> pt1; class point<int> pt2; // redundant use of class
declaration, declarator, expression, function, identifier, private, protected, public, struct, template, type, typename, union, virtual, Chapter 6, Chapter 7