C++ Programming - OOPS Concepts - Discussion
Discussion Forum : OOPS Concepts - General Questions (Q.No. 35)
35.
Which of the following ways are legal to access a class data member using this pointer?
Discussion:
12 comments Page 1 of 2.
Harsh said:
1 month ago
-> operator is used for accessing the pointer type.
But *this.x can also be used as we are de-refencing it?
But *this.x can also be used as we are de-refencing it?
Sagar H Y said:
2 years ago
We have used the arrow operator (- >) for access the class data members using pointer.
ASSIA said:
4 years ago
Please can you hive me an exemple
Garg said:
4 years ago
This pointer contains the address of the object in which we are using this pointer.
Anoimee said:
7 years ago
What is this pointer? Please explain me.
Bhardbj said:
8 years ago
You're right @Nikam.
Hruturaj Nikam said:
1 decade ago
(*this).x is equivalent to this->x.
(1)
Ranjit said:
1 decade ago
But This.x is not allowed in C++ as This is a pointer to the Current object.
It is allowed in C#.
It is allowed in C#.
Ranjit said:
1 decade ago
Hello @Vandana.
The This is a pointer which points to the current object (Through which the function or data member is being called. ).
To access any of the members of the class, we need a object or a pointer to the object.
So you can use This.x.
But when you are treating This as a pointer you should go with This->x.
The This is a pointer which points to the current object (Through which the function or data member is being called. ).
To access any of the members of the class, we need a object or a pointer to the object.
So you can use This.x.
But when you are treating This as a pointer you should go with This->x.
Vandana said:
1 decade ago
Why not this.x?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers