forked from peter-can-write/cpp-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrow-operator.txt
More file actions
39 lines (24 loc) · 795 Bytes
/
arrow-operator.txt
File metadata and controls
39 lines (24 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# arrow-operator
An arrow operator overload should expose the underlying raw pointer
(memory) object. There is special syntax governing the arrow operator in
that it is applied recursively to itself until a pointer is exposed.
class A
{
public:
int* operator->() { return &x; }
const int x = 5;
}
class B
{
public:
A operator->() { return A(); }
}
B b.
b->x // ((b.operator->().)operator->())->x;
13.5.6/1[...] _An expression x->m is interpreted
as (x.operator->())->m for a class object x of type T
if T::operator->() exists and if the operator is selected as the best
match function by the overload resolution
mechanism_ If x->operator->() yields a pointer, it gets dereferenced, if
it yields an object of a type that overloads operator->() that operator
gets called.