Other operators
![]() | 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. |
Operator name | Syntax | Overloadable | Prototype examples (for class T) | |
---|---|---|---|---|
Inside class definition | Outside class definition | |||
function call | a(a1, a2) | Yes | R T::operator()(Arg1 &a1, Arg2 &a2, ... ...); | N/A |
comma | a, b | Yes | T2& T::operator,(T2 &b); | T2& operator,(const T &a, T2 &b); |
conversion | (type) a | Yes | operator type() | N/A |
ternary conditional | a ? b : c | No | N/A | N/A |
Sommaire |
[modifier]Explication
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.
You can help to correct and verify the translation. Click here for instructions.
[modifier]Built-in opérateur d'appel de fonction
E
, suivie d'une liste éventuellement vide de A1, A2, A3, ...
expressions entre parenthèses .E
, followed by a possibly empty list of expressions A1, A2, A3, ...
, in parentheses.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.
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.
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.
E
peuvent être surchargés, résolution de surcharge règles utilisées pour déterminer les surcharges doit être appelé .E
can be overloaded, résolution de surcharge rules used to decide which overload is to be called.You can help to correct and verify the translation. Click here for instructions.
E
spécifie une fonction membre, il peut être virtuel, auquel cas la crosse final de cette fonction sera appelée, à l'aide de dispatch dynamique lors de l'exécution .E
specifies a member function, it may be virtual, in which case the final overrider of that function will be called, using dynamic dispatch at runtime.You can help to correct and verify the translation. Click here for instructions.
A1
, A2
, A3
, etc, à condition que les arguments sont évalués dans un ordre arbitraire, et chaque paramètre de la fonction est initialisée avec son argument correspondant après conversion implicite si nécessaire. Si l'appel est effectué à une fonction membre, alors le pointeur this à l'objet courant est converti comme par conversion explicite au pointeur this attendue par la fonction. L'initialisation et la destruction de chaque paramètre se produit dans le contexte de l'appelant, ce qui signifie, par exemple, que si un paramètre de constructeur de lève une exception près, les gestionnaires d'exceptions définies au sein de la fonction, même en tant que bloc de fonction-essayer, ne sont pas considérés . Si la fonction est une fonction variadique, promotions arguments par défaut sont appliquées à tous les arguments correspondants au paramètre ellipse .A1
, A2
, A3
, etc, provided as arguments are evaluated in arbitrary order, and each function parameter is initialized with its corresponding argument after conversion implicite if neccessary. If the call is made to a member function, then the this pointer to current object is converted as if by explicit cast to the this pointer expected by the function. The initialization and destruction of each parameter occurs in the context of the caller, which means, for example, that if constructor of a parameter throws an exception, the exception handlers defined within the function, even as a function-try block, are not considered. If the function is a variadic function, promotions arguments par défaut are applied to all arguments matched by the ellipsis parameter.You can help to correct and verify the translation. Click here for instructions.
virtual
) mot-clé), même si la fonction primordiale qui est en fait appelée retourne un type différent. Cela permet aux fonctions impérieuses de renvoyer des pointeurs ou des références à des classes dérivées du type de retour renvoyé par la fonction de base, c'est-à C + + supports Les types de retour covariants). Si E
spécifie un destructeur, le type de retour est void .virtual
) keyword), even if the overriding function that's actually called returns a different type. This allows the overriding functions to return pointers or references to classes that are derived from the return type returned by the base function, i.e. C++ supports Les types de retour covariants). If E
specifies a destructor, the return type is void.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.
T
est le nom d'un type .T
is the name of a type.You can help to correct and verify the translation. Click here for instructions.
#include <cstdio>struct S {int f1(double d){ printf("%f \n", d);// variable argument function call}int f2(){ f1(7);// member function call, same as this->f1()// integer argument converted to double}};void f(){ puts("function called");// function call}int main(){ f();// function call S s; s.f2();// member function call}
Résultat :
function called 7.000000
[modifier]Built-in opérateur virgule
E1
expression est évaluée, sa valeur de retour est ignorée et ses effets secondaires sont terminées avant l'évaluation de l'expression commence E2
(à noter que cette capacité est perdue avec défini par l'utilisateur operator,
) . E1
is evaluated, its return value is discarded, and its side effects are completed before evaluation of the expression E2
begins (note that this ability is lost with user-defined operator,
). You can help to correct and verify the translation. Click here for instructions.
E2
.E2
.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.
Résultat :
n = 2 m = 7
[modifier]Built-in opérateur de conversion
expr
conversion explicite à la T
type . expr
and performs explicit cast to the type T
. 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]L'opérateur conditionnel
You can help to correct and verify the translation. Click here for instructions.
LR operator?:(bool, L, R ); | ||
T operator?:(bool, T, T ); | ||
L
et R
. L'opérateur ":" ne peut pas être surchargé, ces signatures de fonction n'existent que dans le but de la résolution de surcharge .L
and R
. The operator “?:” cannot be overloaded, these function signatures only exist for the purpose of overload resolution.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.
You can help to correct and verify the translation. Click here for instructions.
E2
E3
(ou les deux) est un throw-expression, le résultat de l'opérateur conditionnel est le résultat de l'autre (pas jeter) d'expression, et est un prvalue (après lvalue-à-rvalue, array-à-pointeur , ou de la fonction à pointeur de conversion). Un tel opérateur conditionnel est couramment utilisé dans programmation constexpr .E2
or E3
(or both) is a throw-expression, the result of the conditional operator is the result of the other (not throw) expression, and is a prvalue (after lvalue-to-rvalue, array-to-pointer, or function-to-pointer conversion). Such conditional operator is commonly used in programmation constexpr.You can help to correct and verify the translation. Click here for instructions.
E2
ou E3
sont des void type, le résultat est un prvalue de type void .E2
or E3
are of type void, the result is a prvalue of type void.You can help to correct and verify the translation. Click here for instructions.
E2
et E3
ont différents types de classes (ou de même type avec différents cv-qualification) et la catégorie même valeur. Dans ce cas, une tentative est faite pour convertir une (et un seul) des opérandes du type de l'autre, comme suit:E2
and E3
have different class types (or same type with different cv-qualification) and the same value category. In this case, an attempt is made to convert one (and only one) of the operands to the type of the other, as follows: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.
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.
You can help to correct and verify the translation. Click here for instructions.
E2
E3
sont glvalues du même type. Dans ce cas, le résultat est du même type et de la catégorie de valeur .E2
or E3
are glvalues of the same type. In this case, the result has the same type and value category.You can help to correct and verify the translation. Click here for instructions.
E2
ou E3
a le type de classe: la résolution de surcharge est tenté de sélectionner la meilleure conversion d'un type à l'autre .E2
or E3
has class type: overload resolution is attempted to select the best conversion from one type to the other.You can help to correct and verify the translation. Click here for instructions.
E2
ni E3
avez type de classe: tout d'abord, lvalue-à-rvalue, array-à-pointeur et la fonction à pointeur conversions sont appliquées. Puis, E2
nor E3
have class type: first, lvalue-to-rvalue, array-to-pointer, and function-to-pointer conversions are applied. Then, You can help to correct and verify the translation. Click here for instructions.
E2
et E3
maintenant avoir le même type, le résultat est un prvalue temporaire de ce type, la copie initialisée à partir de n'importe quel opérande a été sélectionné après une évaluation E1
E2
and E3
now have the same type, the result is a prvalue temporary of that type, copy-initialized from whatever operand was selected after evaluating E1
You can help to correct and verify the translation. Click here for instructions.
E2
et E3
sont de type arithmétique ou une énumération: conversions arithmétiques habituelles sont appliquées pour les amener à type commun, ce type est le résultat .E2
and E3
have arithmetic or enumeration type: usual arithmetic conversions are applied to bring them to common type, that type is the result.You can help to correct and verify the translation. Click here for instructions.
E2
et E3
sont des pointeurs, ou un pointeur et d'une constante NULL ou un pointeur null constantes les deux, dont l'un est un std::nullptr_t, puis conversions de pointeurs et convrsions de qualification sont appliqués pour les amener à type commun, ce type est le résultat .E2
and E3
are pointers, or a pointer and a null constant, or a both null pointer constants, one of which is a std::nullptr_t, then pointer conversions and qualification convrsions are applied to bring them to common type, that type is the result.You can help to correct and verify the translation. Click here for instructions.
E2
et E3
sont des pointeurs vers les membres, ou un pointeur vers membre et une constante nulle: alors pointeur à membre les conversions et convrsions de qualification sont appliqués pour les amener à type commun, ce type est l' E2
and E3
are pointers to members, or a pointer to member and a null constant: then pointer-to-member conversions and qualification convrsions are applied to bring them to common type, that type is the You can help to correct and verify the translation. Click here for instructions.
#include <string>#include <stdexcept>struct Node { Node* next;int data;// deep-copying copy constructor Node(const Node& other): next(other.next? new Node(*other.next):NULL) , data(other.data){} Node(int d): next(NULL), data(d){} ~Node(){ delete next ;}};int main(){// simple rvalue exampleint n =1>2?10:11;// 1>2 is false, so n = 11// simple lvalue exampleint m =10;(n == m ? n : m)=7;// n == m is false, so m = 7// throw examplestd::string str =2+2==4?"ok":throwstd::logic_error("2+2 != 4");}
[modifier]Bibliothèque standard
operator()
être utilisées comme des objets de fonction .operator()
to be used as function objects.You can help to correct and verify the translation. Click here for instructions.
supprime l'objet ou un tableau Original: deletes the object or array The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::default_delete ) | |
compare ses arguments en utilisant propriétaire fondés sur la sémantique Original: compares its arguments using owner-based semantics The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction) | |
retourne la somme de deux arguments Original: returns the sum of two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::plus ) | |
renvoie la différence entre deux arguments Original: returns the difference between two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::minus ) | |
retourne le produit de deux arguments Original: returns the product of two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::multiplies ) | |
renvoie le résultat de la division du premier argument par le second argument Original: returns the result of the division of the first argument by the second argument The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::divides ) | |
renvoie le reste de la division du premier argument par le second argument Original: returns the remainder from the division of the first argument by the second argument The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::modulus ) | |
renvoie la négation de l'argument Original: returns the negation of the argument The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::negate ) | |
vérifie si les arguments sont égaux Original: checks if the arguments are equal The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::equal_to ) | |
vérifie si les arguments ne sont pas égaux Original: checks if the arguments are not equal The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::not_equal_to ) | |
vérifie si le premier argument est supérieur au second Original: checks if the first argument is greater than the second The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::greater ) | |
vérifie si le premier argument est inférieure à la seconde Original: checks if the first argument is less than the second The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::less ) | |
vérifie si le premier argument est supérieur ou égal à la seconde Original: checks if the first argument is greater than or equal to the second The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::greater_equal ) | |
vérifie si le premier argument est inférieur ou égal à la seconde Original: checks if the first argument is less than or equal to the second The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::less_equal ) | |
retourne le ET logique des deux arguments Original: returns the logical AND of the two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::logical_and ) | |
retourne le OU logique des deux arguments Original: returns the logical OR of the two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::logical_or ) | |
retourne le NOT logique de l'argument Original: returns the logical NOT of the argument The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::logical_not ) | |
renvoie le résultat de ET bit à bit de deux arguments Original: returns the result of bitwise AND of two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::bit_and ) | |
renvoie le résultat d'un OU binaire de deux arguments Original: returns the result of bitwise OR of two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::bit_or ) | |
renvoie le résultat de bit XOR de deux arguments Original: returns the result of bitwise XOR of two arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::bit_xor ) | |
renvoie le complément logique de la suite d'un appel à l'attribut stocké Original: returns the logical complement of the result of a call to the stored predicate The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::unary_negate ) | |
renvoie le complément logique de la suite d'un appel à l'attribut stocké Original: returns the logical complement of the result of a call to the stored predicate The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::binary_negate ) | |
appelle la fonction mémorisée Original: calls the stored function The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::reference_wrapper ) | |
compare lexicographiquement deux chaînes en utilisant les facettes de ce lieu de rassembler Original: lexicographically compares two strings using this locale's collate facet The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::locale ) | |
compare deux valeurs de value_type typeOriginal: compares two values of type value_type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::map::value_compare ) | |
compare deux valeurs de value_type typeOriginal: compares two values of type value_type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::multimap::value_compare ) | |
exécute la fonction Original: executes the function The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::packaged_task ) | |
avancées état du moteur et retourne la valeur générée Original: advances the engine's state and returns the generated value The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::linear_congruential_engine ) | |
génère le nombre aléatoire suivant dans la distribution Original: generates the next random number in the distribution The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::uniform_int_distribution ) |
You can help to correct and verify the translation. Click here for instructions.
vérifie si la valeur est non nulle Original: checks if the value is non-zero The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::error_code ) | |
vérifie si la valeur est non nulle Original: checks if the value is non-zero The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::error_condition ) | |
accède à l'élément de la bitset Original: accesses the element of the bitset The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::bitset::reference ) | |
accède à l'élément de la <bool> vecteur Original: accesses the element of the vector<bool> The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::vector<bool>::reference ) | |
vérifie si un objet est actuellement géré (fonction membre publique de std::unique_ptr ) | |
vérifie si il est associé objet géré Original: checks if there is associated managed object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::shared_ptr ) | |
accède à la référence mémorisée Original: accesses the stored reference The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::reference_wrapper ) | |
convertit l'objet en value_type , retourne value Original: converts the object to value_type , returns value The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::integral_constant ) | |
(avant C++11) (depuis C++11) | vérifie si aucune erreur ne s'est produite (synonyme de !fail()) Original: checks if no error has occurred (synonym of !fail()) The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::basic_ios ) |
convertit le type chaîne sous-jacente Original: converts to the underlying string type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::sub_match ) | |
charge une valeur d'un objet atomique Original: loads a value from an atomic object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::atomic ) | |
teste si la serrure possède sa mutex associé Original: tests whether the lock owns its associated mutex The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::unique_lock ) | |
convertit le pointeur managé à un pointeur de type différent Original: converts the managed pointer to a pointer to different type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (fonction membre publique de std::auto_ptr ) |
operator,
dans boost.assign, boost.spirit, et d'autres bibliothèques .operator,
in boost.assign, boost.spirit, and other libraries.You can help to correct and verify the translation. Click here for instructions.
[modifier]Voir aussi
Opérateurs ordinaires | ||||||
---|---|---|---|---|---|---|
affectation | incrémentation décrémentation | arithmétique | logique | comparaison | accès aux membre | autre |
a = b | ++a | +a | !a | a == b | a[b] | a(...) |
Opérateurs spéciaux | ||||||
static_cast convertit un type dans un autre type compatible dynamic_cast convertit une classe de base virtuelle dans une classe dérivée const_cast convertit un type dans un type compatible avec des cv-qualifiers différents reinterpret_cast convertit un type dans un type incompatibles new allocation de la mémoire delete libère de la mémoire sizeof récupère la taille d'un type sizeof... récupère la taille d'un paquet de paramètres (depuis C++11) typeid récupère les informations de type d'un type noexcept vérifie si une expression peut lancer une exception (depuis C++11) alignof récupère les conditions d'alignement d'un type (depuis C++11) |