Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

this is not a real pointer?

Tags:

c++

pointers

this

I am reading something about virtual table. When it comes to pointer __vptr, it is stated that by the author

Unlike the *this pointer, which is actually a function parameter used by the compiler to resolve self-references, *__vptr is a real pointer. Consequently, it makes each class object allocated bigger by the size of one pointer.

What does it mean here by saying this is actually a function parameter? And this is not a real pointer?

like image 858
Allanqunzi Avatar asked Dec 25 '22 17:12

Allanqunzi


1 Answers

Both pointers are real in the sense that they store an address of something else in memory. By "real" the author means "stored within the class", as opposed to this pointer, which is passed to member functions without being stored in the object itself. Essentially, the pointer to __vptr is part of the object, while this pointer is not.

like image 67
Sergey Kalinichenko Avatar answered Jan 10 '23 13:01

Sergey Kalinichenko