Click here to Skip to main content
15,849,907 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, am trying to learning this pointer in much deep results am missing something. can u help me for that depth.

My understand,
1). This pointer will holds the object of address, that address pass into the non-static function.
2). we can delete the pointer through Dereference of object.

Any more, points required???

What I have tried:

Trying to learn the this pointer, but not getting clearly.

Please, feel free to Google for the many, many available resources about this very topic on the web. See, for instance: The this pointer | Microsoft Learn[^].
Share this answer
You must understand that pointers are ONLY some memory address like a city address. And you must know what type of data or objects you may find there. Like the city address may be a house, a parking lot or only some bushes.
So when you have some pointers, you always need some data or object to which it points.
Some simple example:
int *pointer = NULL; // doesnt point to any object
int *pointer2 = new int;// points to some int memory
*pointer2 = 2;// fills that  int memory with a 2
For that reason it is best to ALWAYS work with typed pointers.

Read some good pointer tutorial to understand it.

Be very careful when casting pointers. It is a common cause for headaches and broken hardware.
Share this answer
this always refers to the current instance of the containing class.
Think of it as a car: you have your car, I have my car. If you put your mobile in the glove box of your car, you don't expect to find it in the glove box of my car because you understand that the two vehicles are separate instances of the class "car".

But ... you can also say "this car" and it can refer to any instance of a car: if you are pointing at your car then you would find the mobile, if you point at my car, you find a locking wheel nut key, a box of nitrile gloves, face masks - but no mobile.

It's the same with classes: this can refer to any class instance; you don't have to pass it to your function explicitly (in fact you can't change it) as the system sets it to the instance when you use the instance to call the function:
Car myCar;
Car yourCar;
Inside the OpenGloveBox function you use this to refer to the specific vehicle, without having to know which one is being referred to.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900