virtual function specifier
提供: cppreference.com
|
|
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
関数は仮想であることを指定します
Original:
Specifies that a function is virtual
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目次 |
[編集] 構文
virtual function_declaration ;
|
|||||||||
[編集] 説明
仮想関数では、動作が派生クラスでオーバーライドできるメンバ関数です。非仮想関数とは対照的に、クラスの実際の型についてのコンパイル時の情報が含まれていない場合であっても、上書きされた動作が維持されます。これは派生クラスが基底クラスへのポインタまたは参照を使用して処理されている場合でも、オーバーライドされた仮想関数の呼び出しは、派生クラスで定義された動作を呼び出すことを意味.
Original:
Virtual functions are member functions whose behavior can be overridden in derived classes. As opposed to non-virtual functions, the overridden behavior is preserved even if there is no compile-time information about the actual type of the class. That means, even if a derived class is handled using pointer or reference to the base class, a call to a overridden virtual function would invoke the behavior defined in the derived class.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
関数のシグネチャはオーバーライド可能にするために同じでなければなりません。
| This section is incomplete Reason: handling of function signatures (member lookup rules) |
Original:
The function signature must be the same in order to be overridden.
| This section is incomplete Reason: handling of function signatures (member lookup rules) |
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
オーバーライドする仮想関数の戻り値の型は必ずしもオーバーライドされた関数のものと同一である必要はありません。彼らはそれぞれ別のもの'共変であれば種類は異なってもかまいません。彼らは、次の要件を満たす場合に二つのタイプが共変のとおりです
Original:
The return type of a overriding virtual function doesn't necessarily need to be the identical to that of the overridden function. The types can be different if they are covariant with each another. Two types are covariant if they satisfy the following requirements:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
- ここでは、
Derived::f()としてオーバーライド関数へとBase::f()としてオーバーライドされた関数を参照されたいOriginal:Here we refer to the overriding function asDerived::f()and to the overridden function asBase::f()The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
- 両方のタイプのクラスへのポインタまたは参照されています。マルチレベルのポインタや参照は許可されていません.Original:both types are pointers or references to classes. Multi-level pointers or references are not allowed.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. -
Base::f()の戻り値の型のクラスはDerived::f()の戻り値の型のクラスの明確かつアクセス可能な直接または間接基本クラスである必要があります.Original:the class of the return type ofBase::f()must be a unambiguous and accessible direct or indirect base class of the class of the return type ofDerived::f().The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions. -
Derived::f()の戻り値の型はCV修飾の戻り値の型より均等に以下Base::f()でなければなりません.Original:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
仮想関数が直接に呼び出される場合、それは、明示的であるし、仮想呼び出しメカニズムが抑制され、その特定の実装が呼び出され、それがメンバーになっているクラスの予選.
Original:
If a virtual function is called directly, that is, explicitly qualifying the class it is a member of, then the virtual call mechanism is suppressed and that particular implementation is called.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
基底クラスの仮想デストラクタは、そのデストラクタはそうでなければ継承されていない場合でも、常に派生クラスのデストラクタでオーバーライドされています.
Original:
A virtual destructor of a base class is always overridden by a destructor of a derived class, even though that destructors are otherwise not inherited.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
仮想関数へのアクセスルールは最初の宣言によって決定されます。オーバーライドする関数の宣言で定義されたアクセスルールは、直接の関数呼び出しにのみ適用されます.
Original:
The access rules to a virtual function are determined by the first declaration. Access rules defined by the declarations of the overriding functions apply only to the direct function calls.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
virtual関数指定子は、メンバーシップを意味し、このようにして唯一のメンバ関数は、仮想することができます。クラスのインスタンスは仮想関数を呼び出すために必要であるためにも、仮想関数はstaticすることはできません.Original:
virtual function specifier implies membership, thus only member functions can be virtual. Also, since an instance of a class is needed in order to call a virtual function, virtual function can not be static.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
関数テンプレートは
virtual宣言することはできません。これは、自分だけのテンプレートである関数に適用されます - クラステンプレートのレギュラーメンバー関数は、仮想宣言することができます.Original:
Functions templates cannot be declared
virtual. This applies only to functions that are themselves templates - a regular member function of a class template can be declared virtual.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集] 例
このコードを実行します
class Parent { public: void functionA(); virtual void functionB(); //Note the keyword virtual void functionC(); }; class Child : public Parent { public: void functionA(); virtual void functionB(); //Note the keyword virtual }; int main() { Parent* p1 = new Parent; Parent* p2 = new Child; Child* c = new Child; p1->functionA(); //Calls Parent::functionA p1->functionB(); //Calls Parent::functionB p1->functionC(); //Calls Parent::functionC p2->functionA(); //Calls Parent::functionA because p2 points to a Parent p2->functionB(); //Calls Child::functionB even though p2 points // to a Parent because functionB is virtual p2->functionC(); //Calls Parent::functionC c->functionA(); //Calls Child::functionA c->functionB(); //Calls Child::functionB c->functionC(); //Calls Parent::functionC return 0; }
[編集] 参照
- 指定子をオーバーライドします (C++11およびそれ以降)
- 最後の子 (C++11およびそれ以降)