Created
July 5, 2015 10:02
-
-
Save krysseltillada/9973a6078731e92f8b77 to your computer and use it in GitHub Desktop.
(*this).data_member && this->data_member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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