Skip to content

Instantly share code, notes, and snippets.

@karubabu
Last active August 29, 2015 14:12
Show Gist options
  • Save karubabu/ff2687bbaeaa57b3bb79 to your computer and use it in GitHub Desktop.
Save karubabu/ff2687bbaeaa57b3bb79 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
class Acls {
public:
int a;
void disp(){ cout << "Acls: a=" << a << endl; }
};
class Bcls: public Acls {
public:
int b;
void disp(){ cout << "Bcls: a=" << a << " b=" << b << endl; }
};
int main(){
Acls* ap;
Bcls bd;
bd.a = 10;
bd.b = 20;
ap = &bd;
ap->disp();
return 0;
}
//実際の出力はAcls: a=10
//本での出力はAcls: a=20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment