+ 7
Explain self reference pointer
7 ответов
+ 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
};
+ 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?
+ 3
Ketan Lalcheta your right, good explanation.
+ 2
https://code.sololearn.com/c898HcCPPVkz/?ref=app a clear example
+ 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
+ 1
a pointer to its own type construction, eg: "this" is a class pointer to the current object of its type.
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...