I have a few questions (Valmont) about using the this Pointer. I'm trying to understand more about how it's working under the hood. Let me start with some code:
Example class and main()
Code:
#include <iostream>
using std::cout;
class Example
{
public:
Example(int = 0);
void print() const;
private:
int data;
};
Example::Example(int x)
: data(x)
{}
void Example::print() const
{
// Implicitly use this pointer
cout << "data = " << data << "\n";
// Explicitly use this pointer
cout << "this->data = " << this->data << "\n";
}
int main()
{
Example obj_one(150);
obj_one.print();
return 0;
}
And the program output...
Code:
data = 150
this->data = 150
To me it seems like implicit vs. explicit use of the
this pointer is actually the exact same under the hood. Right now I'm under the assumption that the compiler would be converting implicit calls to explicit calls at the time of compilation, can you tell me if this is correct?
Also if anyone wants to add anything that might aid in my understanding of
this that would also be appreciated.