Skip to content

Instantly share code, notes, and snippets.

@TheBuzzSaw
Created December 8, 2016 18:37
Show Gist options
  • Select an option

  • Save TheBuzzSaw/0eee5879aa4d7e75362d419b4d8dba86 to your computer and use it in GitHub Desktop.

Select an option

Save TheBuzzSaw/0eee5879aa4d7e75362d419b4d8dba86 to your computer and use it in GitHub Desktop.
Trick C++ Question
#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