Created
December 8, 2016 18:37
-
-
Save TheBuzzSaw/0eee5879aa4d7e75362d419b4d8dba86 to your computer and use it in GitHub Desktop.
Trick C++ Question
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 <iostream> | |
| using namespace std; | |
| class Base | |
| { | |
| int _value; | |
| public: | |
| Base() | |
| { | |
| _value = GenerateValue(); | |
| } | |
| virtual int GenerateValue() | |
| { | |
| return 1; | |
| } | |
| int GetValue() | |
| { | |
| return _value; | |
| } | |
| }; | |
| class Derived : public Base | |
| { | |
| public: | |
| virtual int GenerateValue() | |
| { | |
| return 2; | |
| } | |
| }; | |
| int main() | |
| { | |
| Derived d; | |
| cout << d.GetValue() << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment