Member access operators — cppreference.com
<metanoindex/>
Accède à un membre d'un objet .
Original:
Accesses a member of an object.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
| Operator name | Syntax | Overloadable | Prototype examples (for class T)
| |
|---|---|---|---|---|
| Inside class definition | Outside class definition | |||
| array subscript | a[b]
|
Yes | R& T::operator[](const T2& b);
|
N/A |
indirection (variable pointed to by a)
|
*a
|
Yes | R& T::operator*();
|
R& operator*(T &a);
|
| address of | &a
|
Yes | R* T::operator&();
|
R* operator&(T &a);
|
| member of object | a.b
|
No | N/A | N/A |
| member of pointer | a->b
|
Yes | R* T::operator->()
|
N/A |
| pointer to member of object | a.*b
|
No | N/A | N/A |
| pointer to member of pointer | a->*b
|
Yes | R* T::operator->*(R)
|
R* T::operator->*(T, R)
|
| ||||
Explication
Tableau' indice opérateur permet d'accéder aux éléments de la matrice interne
Original:
array subscript operator provides access to the elements in the internal array
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Indirection', membre du pointeur et pointeur de membre du pointeur opérateurs fournissent sémantique de pointeur pour n'importe quel objet .
Original:
indirection, member of pointer and pointer to member of pointer operators provide pointer semantics for any object.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Membre du pointeur' et le pointeur de membre du pointeur opérateurs renvoient un pointeur sur l'objet réel qui sera utilisé pour l'accès des membres .
Original:
member of pointer and pointer to member of pointer operators return a pointer to the actual object which will be used for member access.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Built-in opérateur d'indice
Pour chaque type d'objet T (peut-cv-qualifié), la signature de la fonction suivante participe à la résolution de surcharge:
Original:
For every object type T (possibly cv-qualified), the following function signature participates in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
<tbody> </tbody>
|
|
||
|
|
||
Les opérande non-pointeur peut être n'importe quelle expression de type énumération intégrale ou sans portée, il est implicitement convertie à std::ptrdiff_t. L'expression A[B] est exactement identique à la *(A+B) expression, qui est, le pointeur d'opérande (qui peut être le résultat d'ensemble à aiguille de conversion, et qui doit être orientée vers un élément de tableau ou d'une certaine delà de l'extrémité) est ajusté à point à un autre élément du même réseau, suivant les règles de arithmétique de pointeurs, et est alors déréférencé .
Original:
The non-pointer operand may be any expression of integral or unscoped enumeration type, it is implicitement convertie to std::ptrdiff_t. The expression A[B] is exactly identical to the expression *(A+B), that is, the pointer operand (which may be a result of array-to-pointer conversion, and which must point to an element of some array or one past the end) is adjusted to point at another element of the same array, following the rules of arithmétique de pointeurs, and is then dereferenced.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream> int main() { int a[4] = {1,2,3,4}; int* p = &a[2]; std::cout << p[1] << p[-1] << 1[p] << (-1)[p] << '\n'; }
Résultat :
Built-in opérateur d'indirection
Pour chaque type de T qui est soit de type d'un objet (cv-qualifié) ou de type de fonction (const pas ou ref-qualifié), la signature de la fonction suivante participe à la résolution de surcharge:
Original:
For every type T that is either object type (possibly cv-qualified) or function type (not const- or ref-qualified), the following function signature participates in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
<tbody> </tbody>
L'opérande de l'opérateur d'indirection intégré est un pointeur sur l'objet ou la fonction, et le résultat est la lvalue que le pointeur pointe du doigt. Notez qu'un pointeur de type incomplet peut être déréférencé, par exemple, lors de l'initialisation d'une référence .
Original:
The operand of the built-in indirection operator is a pointer to object or function, and the result is the lvalue that the pointer is pointing at. Note that a pointer to incomplete type can be dereferenced, e.g. when initializing a reference.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream> int f() { return 42; } int main() { int n = 1; int* pn = &n; int& r = *pn; // lvalue can be bound to a reference int m = *pn; // indirection + lvalue-to-rvalue conversion int (*fp)() = &f; int (&fr)() = *fp; // function lvalue can be bound to a reference }
Built-in-adresse de l'opérateur
L'opérande du haut-operator& est soit une expression lvalue de n'importe quel type ou le nom qualifié d'une fonction membre non statique / object d'une certaine classe. Cet opérateur ne participe pas à la résolution de surcharge, des règles spéciales sont utilisées:
Original:
The operand of the built-in operator& is either an lvalue expression of any type or the qualified name of a non-static member function/object in some class. This operator does not participate in overload resolution, special rules are used:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si l'opérande est l'expression d'un certain type lvalue T, operator& crée et retourne un prvalue de T* type, avec la même qualification cv, qui est dirigée vers l'objet désigné par l'opérande. Si l'opérande a un type incomplet, le pointeur peut être formé, mais si ce type incomplet se trouve être une classe qui définit son propre operator&, le comportement est indéfini. Pour les opérandes de type défini par l'utilisateur avec operator&, std::addressof peut être utilisé pour obtenir le pointeur de la vraie .
Original:
If the operand is an lvalue expression of some type T, operator& creates and returns a prvalue of type T*, with the same cv qualification, that is pointing at the object designated by the operand. If the operand has incomplete type, the pointer can be formed, but if that incomplete type happens to be a class that defines its own operator&, the behavior is undefined. For the operands of type with user-defined operator&, std::addressof may be used to obtain the true pointer.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si l'opérande est le nom d'une fonction surchargée, l'adresse peut être prise que si la surcharge peut être résolu en raison du contexte, qui est le résultat de operator&' est utilisé pour initialiser un objet, une expression de cast, sur la gauche de l'affectation, comme paramètre de fonction ou une instruction return .
Original:
If the operand is the name of an overloaded function, the address may be taken only if the overload can be resolved due to context, that is, the result of operator& is used to initialize an object, in a cast expression, on the left of an assignment, as a function parameter or in a return statement.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Si l'opérande est un nom qualifié d'un membre non-statique, par exemple, &Class::member, le résultat est un pointeur vers une fonction membre prvalue ou un pointeur vers l'objet membre de T type C classe. Notez que ni &member ni Class::member ni même (&Class::member) peut être utilisé pour initialiser un pointeur vers membre .
Original:
If the operand is a qualified name of a non-static member, e.g. &Class::member, the result is a prvalue pointer to member function or pointer to member object of type T in class C. Note that neither &member nor Class::member nor even (&Class::member) may be used to initialize a pointer to member.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
void f(int) {} void f(double) {} struct A { int i; }; struct B { void f(); }; int main() { int n = 1; int* pn = &n; // pointer int A::* mp = &A::i; // pointer to member object void (B::*mpf)() = &B::f; // pointer to member function // auto pf2 = &f; // error: ambiguous overloaded function type void (*pf)(int) = &f; // overload resolution due to initialization auto pf2 = static_cast<void(*)(int)>(&f); // overload resolution due to cast }
Built-in des opérateurs d'accès des membres
L'opérande gauche de l'haut-operator. et operator-> est une expression de type classe complète T (pour operator.) ou un pointeur pour compléter type de classe T* (pour operator->, qui est évalué avant l'opérateur peut être appelé. L'opérande de droite est le nom d'un objet ou élément de fonction de membre ou d'une T de classes de base de T, par exemple expr.member, éventuellement qualifié, par exemple expr.name::member, éventuellement préfixé par le mot' modèle, par exemple expr.template member .
Original:
The left operand of the built-in operator. and operator-> is an expression of complete class type T (for operator.) or pointer to complete class type T* (for operator->, which is evaluated before the operator can be called. The right operand is the name of a member object or member function of T or of one of T's base classes, e.g. expr.member, optionally qualified, e.g. expr.name::member, optionally prepended by the keyword template, e.g. expr.template member.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
L'expression A->B est exactement équivalent à (*A).B de types intégrés. Si un operator-> défini par l'utilisateur est fourni, operator-> est de nouveau appelée sur la valeur qu'elle retourne, de façon récursive, jusqu'à ce que le operator-> est atteint qui retourne un pointeur ordinaire. Après cela, la sémantique défaut sont appliquées à ce pointeur .
Original:
The expression A->B is exactly equivalent to (*A).B for builtin types. If a user-defined operator-> is provided, operator-> is called again on the value that it returns, recursively, until the operator-> is reached that returns a plain pointer. After that, builtin semantics are applied to that pointer.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Dans le expr.B expression
Original:
In the expression expr.B,
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
si B a T& type, le résultat est une lvalue T .
Original:
if B has type T&, the result is an lvalue T.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
B si c'est un membre de données statiques de T type, le résultat est une lvalue T désignant ce membre statique de données .
Original:
if B is a static data member of type T, the result is an lvalue T designating that static data member.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
si B est un membre non statique de données de T type, le résultat est une lvalue si expr est une lvalue, le résultat est xValue si expr est un xValue, et le résultat est un prvalue autrement. Si B n'est pas déclarée être membre mutable', les CV-qualification du résultat est l'union de CV-qualification des expr et B. Si B est mutable, les CV-qualification du résultat est l'union de volatiles-qualifications .
Original:
if B is a non-static data member of type T, the result is an lvalue if expr is an lvalue, the result is xvalue if expr is an xvalue, and the result is a prvalue otherwise. If B is not declared to be a mutable member, the cv-qualification of the result is the union of cv-qualifications of expr and B. If B is mutable, the cv-qualification of the result is the union of volatile-qualifications.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4)
si B est une fonction membre statique, le résultat est une lvalue désignant la fonction memeber statique. Essentiellement, expr est évalué et mis au rebut dans cette affaire .
Original:
if B is a static member function, the result is an lvalue designating the static memeber function. Essentially, expr is evaluated and discarded in this case.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
5)
si B est une fonction membre non statique, le résultat est un type spécial de prvalue qui ne peuvent être utilisés comme opérande gauche d'une expression d'appel de fonction, et à aucune autre fin .
Original:
if B is a non-static member function, the result is a special kind of prvalue that can only be used as the left-hand operand in a function-call expression, and for no other purpose.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
6)
si B est une énumération membre, le résultat est un prvalue de la .
Original:
if B is a member enumeration, the result is a prvalue of the.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
7)
si B est un type imbriqué, le programme est mal formé (ne sera pas compilé)
Original:
if B is a nested type, the program is ill-formed (won't compile)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
8)
si expr est de type scalaire non-classe et B est le nom du type ou decltype spécificateur désignant du même type (moins cv-qualification), alors le résultat est un type spécial de prvalue qui ne peuvent être utilisés comme opérande gauche dans un appel de fonction, d'expression, et à aucune autre fin. L'appel de fonction est appelé appel destructeur pseudo ', il ne prend aucun argument, les retours void, et n'effectue aucune action autre que l'évaluation initiale de expr .
Original:
if expr has non-class scalar type and B is the type name or decltype specifier designating the same type (minus cv-qualifications), then the result is a special kind of prvalue that can only be used as the left-hand operand in a function-call expression, and for no other purpose. The function call is called pseudo destructor call', it takes no arguments, returns void, and performs no action other than initial evaluation of expr.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream> template<typename T> struct P { typedef T* ptr; }; template<typename T> struct A { class B {}; enum E {RED = 1, BLUE = 2}; int n; static int sn; int f() { return 10+n; } static int fs() { return 4; } A(int n) : n(n) {} // keyword template needed to refer to a dependent template member void g() { T obj; int* p = obj.template ptr<int>; p->~T(); // T is int, this calls int's pseudo destructor } }; template<> int A<P<int>>::sn = 2; int main() { A<P<int>> a(1); std::cout << a.n << ' ' << a.sn << ' ' // << A::sn also works << a.f() << ' ' << a.fs() << ' ' // A::fs() also works << a.RED << ' ' // nested type not allowed // << a.B // nested type not allowed ; }
Résultat :
Built-in des opérateurs d'accès pointeur à membre
L'opérande de droite des deux operator.* et operator->* est une expression de type pointeur sur un membre en T classe. Pour operator.*, l'opérande de gauche est une expression de T type de classe ou d'une classe dérivée dans laquelle T est sans ambiguïté base accessible. Pour operator->*, l'opérande de gauche est un pointeur vers T ou à sa base .
Original:
The right operand of both operator.* and operator->* is an expression of type pointer to member in class T. For operator.*, the left operand is an expression of class type T, or of some derived class in which T is unambiguous accessible base. For operator->*, the left operand is a pointer to T or to its base.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Pour chaque combinaison de types de B, D, T, où D est soit le même que B ou une classe dérivée de B et T est soit objet ou type de fonction, la signature de la fonction suivante participe à la résolution de surcharge:
Original:
For every combination of types B, D, T, where D is either the same as B or a class derived from B, and T is either object or function type, the following function signature participates in overload resolution:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
<tbody> </tbody>
|
|
||
où les deux opérandes peuvent être cv-qualifié, dans ce cas, le type de retour de cv-qualification est l'union de la cv-qualification des opérandes .
Original:
where both operands may be cv-qualified, in which case the return type's cv-qualification is the union of the cv-qualification of the operands.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Le E1->*E2 expression est exactement équivalent à (*E1).*E2 de types intégrés .
Original:
The expression E1->*E2 is exactly equivalent to (*E1).*E2 for built-in types.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Pour la expr.*ptr expression
Original:
For the expression expr.*ptr,
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
Si le type dynamique de expr ne contient pas l'élément auquel se réfère ptr, le comportement n'est pas défini
Original:
If the dynamic type of expr does not contain the member to which ptr refers, the behavior is undefined
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
cv-qualification règles sont les mêmes que pour l'opérateur de l'accès des membres, avec une règle supplémentaire: un pointeur vers le membre qui fait référence à un membre mutable ne peut pas être utilisé pour modifier cet élément dans un objet const .
Original:
cv-qualification rules are the same as for member access operator, with one additional rule: a pointer to member that refers to a mutable member cannot be used to modify that member in a const object.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4)
Si expr est des points rvalue et ptr à une fonction membre avec & ref-qualification, le programme est mal formé
Original:
If expr is rvalue and ptr points to a member function with & ref-qualifier, the program is ill-formed
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
5)
Si expr est lvalue et les points ptr à une fonction membre avec && ref-qualification, le programme est mal formé
Original:
If expr is lvalue and ptr points to a member function with && ref-qualifier, the program is ill-formed
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
6)
Le résultat de expr.*ptr où ptr est un pointeur vers un membre de la catégorie de données a la même valeur que expr .
Original:
The result of expr.*ptr where ptr is a pointer to data member has the same value category as expr.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
7)
Le résultat de expr.*ptr où ptr est un pointeur vers une fonction membre est une sorte de specail prvalue qui ne peut être utilisée comme argument gauche d'une expression appel de fonction et à aucune autre fin .
Original:
The result of expr.*ptr where ptr is a pointer to member function is a specail kind of prvalue that may only be used as the left-hand argument of a function call expression and for no other purpose.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
8)
Si ptr est une valeur de pointeur null, le comportement est indéfini
Original:
If ptr is a null pointer value, the behavior is undefined
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
#include <iostream> struct S { mutable int mi; int f(int n) { return mi+n; } S(int n) : mi(n) {} }; struct D : public S { D(int n) : S(n) {} }; int main() { int S::* pmi = &S::mi; int (S::*mpf)(int) = &S::f; const S s(7); // s.*pmi = 10; // cannot modify through mutable std::cout << s.*pmi << '\n'; D d(7); // base pointers work with derived object D* dp = &d; std::cout << (d.*mpf)(7) << ' ' << (dp->*mpf)(8) << '\n'; }
Résultat :
Bibliothèque standard
Opérateur d'indice est surchargé par de nombreuses classes de conteneurs standard
Original:
Subscript operator is overloaded by many standard container classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
accède bit spécifique Original: accesses specific bit The text has been machine-translated via Google Translate. (fonction membre publique de std::bitset) [edit]
| |
fournit un accès indexé à la matrice gérée Original: provides indexed access to the managed array The text has been machine-translated via Google Translate. (fonction membre publique de std::unique_ptr) [edit]
| |
| accède au caractère spécifié (fonction membre publique de std::basic_string) [edit]
| |
| accède à l'élément spécifié (fonction membre publique de std::array) [edit]
| |
| accède à l'élément spécifié (fonction membre publique de std::deque) [edit]
| |
| accède à l'élément spécifié (fonction membre publique de std::vector) [edit]
| |
| accède à l'élément spécifié (fonction membre publique de std::map) [edit]
| |
| accède à l'élément spécifié (fonction membre publique de std::unordered_map) [edit]
| |
accède à un élément de l'index Original: accesses an element by index The text has been machine-translated via Google Translate. (fonction membre publique de std::reverse_iterator) [edit]
| |
obtient de référence rvalue à l'élément indexé Original: obtains rvalue reference to indexed element The text has been machine-translated via Google Translate. (fonction membre publique de std::move_iterator)
| |
get / set élément valarray, tranche, ou un masque Original: get/set valarray element, slice, or mask The text has been machine-translated via Google Translate. (fonction membre publique de std::valarray) [edit]
| |
rendement indiqués correspondent à des sous- Original: returns specified sub-match The text has been machine-translated via Google Translate. (fonction membre publique de std::match_results) [edit]
| |
Les opérateurs d'accès indirection et membre sont surchargés par de nombreux itérateurs et les classes de pointeurs intelligents
Original:
The indirection and member access operators are overloaded by many iterators and smart pointer classes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
déréférence le pointeur à l'objet géré Original: dereferences pointer to the managed object The text has been machine-translated via Google Translate. (fonction membre publique de std::unique_ptr) [edit]
| |
déréférence le pointeur à l'objet géré Original: dereferences pointer to the managed object The text has been machine-translated via Google Translate. (fonction membre publique de std::shared_ptr) [edit]
| |
accède à l'objet géré Original: accesses the managed object The text has been machine-translated via Google Translate. (fonction membre publique de std::auto_ptr)
| |
retourne une référence à la présente raw_storage_iterator Original: returns a reference to this raw_storage_iterator The text has been machine-translated via Google Translate. (fonction membre publique de std::raw_storage_iterator)
| |
déréférence l'itérateur décrémenté sous-jacent Original: dereferences the decremented underlying iterator The text has been machine-translated via Google Translate. (fonction membre publique de std::reverse_iterator) [edit]
| |
| no-op (fonction membre publique de std::back_insert_iterator)
| |
| no-op (fonction membre publique de std::front_insert_iterator)
| |
| no-op (fonction membre publique de std::insert_iterator)
| |
accède à l'élément pointé vers Original: accesses the pointed-to element The text has been machine-translated via Google Translate. (fonction membre publique de std::move_iterator)
| |
obtient une copie du courant element Original: obtains a copy of the current element The text has been machine-translated via Google Translate. (fonction membre publique de std::istream_iterator)
| |
| no-op (fonction membre publique de std::ostream_iterator)
| |
(depuis C++11) |
obtient une copie du courant character Original: obtains a copy of the current character The text has been machine-translated via Google Translate. (fonction membre publique de std::istreambuf_iterator)
|
| no-op (fonction membre publique de std::ostreambuf_iterator)
| |
accède aux match Original: accesses the current match The text has been machine-translated via Google Translate. (fonction membre publique de std::regex_iterator)
| |
accède au courant result Original: accesses the current result The text has been machine-translated via Google Translate. (fonction membre publique de std::regex_token_iterator)
| |
{{{1}}}
Original:
{{{2}}}
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Voir aussi
| Opérateurs ordinaires | ||||||
|---|---|---|---|---|---|---|
| affectation | incrémentation décrémentation |
arithmétique | logique | comparaison | accès aux membre | autre |
|
|
|
|
|
|
|
|
| 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) | ||||||