Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created July 5, 2015 10:02
Show Gist options
  • Save krysseltillada/9973a6078731e92f8b77 to your computer and use it in GitHub Desktop.
Save krysseltillada/9973a6078731e92f8b77 to your computer and use it in GitHub Desktop.
(*this).data_member && this->data_member
#include <iostream> /// std::cout; std::endl;
#include <string> /// std::string;
struct person
{
void display()
{
std::cout << "name = " << name << std::endl /// this was initialized and takes the address which this points which is p1 implicitly
<< "this->name = " << this->name << std::endl /// this points to an object which is p1 and dereference it and accessing those member which is name
<< "(*this).name = " << (*this).name << std::endl; /// this deference first what this points which is p1 and accessing those member which is name
}
std::string name = "kryssel tillada";
};
int main()
{
person p1;
p1.display();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment