+ 7

Explain self reference pointer

8th Sep 2018, 8:19 AM
Amit Haldiya
Amit Haldiya - avatar
7 Respostas
+ 10
Amit Haldiya member contain pointer of same data type... it means it points to whatever it is part of... for example, class A { int a; int c; A* p;// pointer of class A };
8th Sep 2018, 8:32 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 3
Ketan Lalcheta this pointer is a self reference pointer because it represents the current object internally. are you saying because its not explicitly defined as a class pointer it won't be part of the class? if i were to modify your class and give it a constructor like this: A::A(){ p = this; } does it now mean p is not part of the object anymore?
9th Sep 2018, 3:55 AM
Germain F
Germain F - avatar
+ 3
Ketan Lalcheta your right, good explanation.
9th Sep 2018, 6:05 AM
Germain F
Germain F - avatar
8th Sep 2018, 8:47 PM
Mauro Mile
Mauro Mile - avatar
+ 2
Console if you explicitly declare it , then sizeof class object changes and this pointer size is not counted also.. if you have explicitly created another member of same type, it is upto you to assign other or this pointer...compiler don't force you to allocate specific pointer only... with this pointer as internal pointer to be considered as self reference pointer, all class should be considered as self reference pointer... asiak, self reference pointer are used for linked list implementation and all.. for something to be considered self reference, seperate data member should be there rather than internal this pointer.. P.S. : Additionally this pointer is not class member ... it is associated with objects, not class... if you create static methods, this pointer is not available.... but for class member explicitly as data member, that node (explicit declared member of same type pointer) is available
9th Sep 2018, 5:49 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
a pointer to its own type construction, eg: "this" is a class pointer to the current object of its type.
9th Sep 2018, 3:25 AM
Germain F
Germain F - avatar
0
Console asaik ,we can not consider this pointer as self reference pointer... this pointer represent class object itself... it is not part of class...
9th Sep 2018, 3:38 AM
Ketan Lalcheta
Ketan Lalcheta - avatar