virtual function specifier
De cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Indique qu'une fonction est virtuelle
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.
Sommaire |
[modifier] Syntaxe
virtual function_declaration ;
|
|||||||||
[modifier] Explication
Fonctions virtuelles sont des fonctions membres dont le comportement peut être redéfinie dans les classes dérivées. Par opposition aux fonctions non virtuelles, le comportement substituée est conservée, même s'il n'y a pas d'information lors de la compilation sur le type réel de la classe. Cela signifie que, même si une classe dérivée est gérée en utilisant pointeur ou une référence à la classe de base, un appel à une fonction virtuelle surchargée invoquerait le comportement défini dans la classe dérivée .
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.
La signature de la fonction doit être la même pour être remplacée.
| 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.
Le type de retour d'une fonction primordiale virtuel ne doit pas nécessairement être identique à celle de la fonction surchargée. Les types peuvent être différents s'ils sont' covariante les uns avec les autres. Deux types sont covariants s'ils satisfont aux exigences suivantes:
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.
- Nous nous référons ici à la fonction primordiale que
Derived::f()et à la fonction surchargée commeBase::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.
- les deux types sont des pointeurs ou des références à des classes. Multi-niveaux pointeurs ou des références ne sont pas autorisés .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. - la classe du type de retour de
Base::f()doit être une classe de base clair et accessible directement ou indirectement de la classe du type de retour deDerived::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. - le type de retour de
Derived::f()doit être égale ou cv-qualifié moins que le type de retour deBase::f().Original:the return type ofDerived::f()must be equally or less cv-qualifié than the return type ofBase::f().The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si une fonction virtuelle est appelée directement, c'est-à-qualification explicitement la classe, il est membre de l', alors le mécanisme d'appel virtuel est supprimée et que la mise en oeuvre particulière est appelé .
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.
Un destructeur virtuel d'une classe de base est toujours remplacée par un destructeur d'une classe dérivée, même si par ailleurs que les destructeurs sont pas héritées .
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.
Les règles d'accès à une fonction virtuelle sont déterminées par la première déclaration. Les règles d'accès définies par les déclarations des fonctions primordiales s'appliquent uniquement aux appels de fonctions directes .
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 fonction spécificateur implique l'adhésion, ainsi que des fonctions membres peuvent être virtuelles. En outre, depuis une instance d'une classe est nécessaire pour appeler une fonction virtuelle, fonction virtuelle ne peut pas être 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.
Modèles de fonctions ne peut être déclarée
virtual. Ceci s'applique seulement aux fonctions qui sont eux-mêmes des modèles - une fonction de membre régulier d'un modèle de classe peut être déclarée virtuelle .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.
[modifier] Exemple
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; }
[modifier] Voir aussi
- remplacer spécificateur (depuis C++11)
- spécificateur finale (depuis C++11)

