Created
May 11, 2013 01:37
-
-
Save scvalex/5558574 to your computer and use it in GitHub Desktop.
Subclassing in C++: overriden fields are not removed, the syntax for accessing them is just unusual. This is not a surprise, since subclassing strictly extends objects.
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 <cstdio> | |
using namespace std; | |
class A { | |
public: | |
int fa; | |
}; | |
class B : public A { | |
public: | |
int fa; | |
int fb; | |
}; | |
int main(int argc, char *argv[]) { | |
B b; | |
b.A::fa = 2; | |
b.fa = 3; | |
b.fb = 5; | |
printf("b.A::fa = %d; b.fa = %d; b.fb = %d\n", b.A::fa, b.fa, b.fb); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Build and run with: