Last active
August 29, 2015 14:05
-
-
Save ixtli/6d20b00a20450324757b to your computer and use it in GitHub Desktop.
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 <stdio.h> | |
| class Person | |
| { | |
| public: | |
| virtual void aboutMe() const { | |
| printf("I am a person.\n"); | |
| } | |
| }; | |
| class Student : public Person | |
| { | |
| public: | |
| void aboutMe() const { | |
| printf("I am a student!\n"); | |
| } | |
| }; | |
| int main(int argc, char** argv) | |
| { | |
| Student s; | |
| Person* p = new Student(); | |
| s.aboutMe(); | |
| ((Person)s).aboutMe(); | |
| p->aboutMe(); | |
| ((Person*)p)->aboutMe(); | |
| return 0; | |
| } | |
| /** | |
| [~] $ clang++ -Wall -Wextra -g -o out main.cpp && ./out | |
| I am a student! | |
| I am a person. | |
| I am a student! | |
| I am a student! | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment