Class declaration
提供: cppreference.com
![]() |
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
目次 |
[編集] 構文
class identifier { class_body } object_list ;
|
(1) | ||||||||
class identifier : ancestor_list { class_body } object_list ;
|
(2) | ||||||||
class identifier ;
|
(3) | ||||||||
class identifier final opt_ancestors_and_body | (4) | (C++11およびそれ以降) | |||||||
[編集] Class Body
A list of member and friend declarations and access specifiers:
public: | (1) | ||||||||
protected: | (2) | ||||||||
private: | (3) | ||||||||
friend friend_declaration | (4) | ||||||||
member_declaration | (5) | ||||||||
static member_declaration | (6) | ||||||||
nested_type_declaration | (7) | ||||||||
[編集] Ancestor List
A list of classes that have already bee fully defined optionally prefixed with an access specifier
[編集] Object List
An optional list of instances of the previously defined class
[編集] 説明
- Defines a class and its member
- Defines a class inheriting other classes
- Forwards declares a class
- 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
[編集] ノート
(C++11およびそれ以降) A default value can be assigned to data members inside the class body (ie: not necessarily in a constructor)
[編集] 参照
[編集] 例
class C; class D : public B // B needs to be defined { private: C *ptr_c; // a pointer/reference to C can be used as C has been forward declared double x = 12.3; // C++11 inline data member initialization static const int sci = 1; // this is valid in C++98 as well public: typedef B parent_type; // inline function virtual parent_type foo() const { return B(); } // non-inline function declaration. needs to be defined externally void bar(); } D_obj; // An object of type D is defined // definition of a class method outside the class void D::bar() { //... }