Possible duplicate:what is the difference between the (.) Dot operator and (->) arrow in C ++
In this book, I study pointers, and I just finished the chapter on OOP (spits on the ground), one way or another, saying that I can use a member select operator like this (->). he said it was like "." except points of objects, not member objects. What difference does it look like it is used the same way ...
Yes, it actually does the same thing, but for different variables.
, ->, , ..
->
.
,
struct mystruct *pointer; struct mystruct var; pointer->field = ... var.field = ...
. , -> . .
:
Foo foo; Foo* pfoo = &foo;
pfoo->mem (*pfoo).mem.
pfoo->mem
(*pfoo).mem
, -: foo.mem (&foo)->mem.
foo.mem
(&foo)->mem
â , :
A* a = new A; a->member();
"." :
A a; a.member();
struct S { int a, b; }; S st; S* pst = &st; st.a = 1; // . takes an object (or reference to one) pst->b = 2; // -> takes a pointer
(MyObject object;), . (, , ..), : object.Member.
MyObject object;
object.Member
(MyObject* pObject = new MyObject();), , . , *. , , - : (*pObject).Member.
MyObject* pObject = new MyObject();
*
(*pObject).Member
, , -> . , pObject->Member.
pObject->Member
object o; object *p = &o; // pointer to object o.member; // access member p->member; // access member through pointer
-> , , . .
class A { public: int x; void g() {}; }; A a; a.x a.g(); A * ap = new A(); ap->x; ap->g();
and you can dereference the pointer and then use .:
(*ap).x; (*ap).g();
Source: https://habr.com/ru/post/1749499/More articles:How can I disable all HTML using markdown (PHP and JS)? - javascriptHow to break code for iOS 3.0 and iOS 3.2 so that I can use MPMoviePlayerViewController if OS 3.2 ++ - iphoneFind all the ways from the root to the leaves of the tree in the scheme - lispHow to programmatically duplicate UIViews built into an interface builder? - objective-cDifference between [object variable] and object.variable in Obj-C? - objective-cHow to keep multiple accessString passwords safe, separate and easy to deploy? - securityValidating a valid WCF certificate with BasicHttpBinding - c #Encryption of connection strings so that other developers cannot decrypt, but the application still has access - .netLocal web applications and W3C standards - phpMake one table equal to another without deleting * - sql-serverAll Articles