Skip to content

Instantly share code, notes, and snippets.

@ixtli
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save ixtli/6d20b00a20450324757b to your computer and use it in GitHub Desktop.

Select an option

Save ixtli/6d20b00a20450324757b to your computer and use it in GitHub Desktop.
#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