Skip to content

Instantly share code, notes, and snippets.

@onqtam
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onqtam/9305109 to your computer and use it in GitHub Desktop.
Save onqtam/9305109 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
struct A {
A() : data(0) {}
virtual void doStuff() {
data++;
cout << "A" << endl;
}
int data;
};
struct B : public A {
virtual void doStuff() {
static_cast<A>(*this).doStuff();
cout << "B" << endl;
data--;
}
};
int main(int argc, char** argv) {
B temp;
static_cast<A*>(&temp)->doStuff();
cout << temp.data << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment