Skip to content

Instantly share code, notes, and snippets.

@lettergram
Created March 19, 2015 00:48
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 lettergram/fc03d870fa34eb60d6df to your computer and use it in GitHub Desktop.
Save lettergram/fc03d870fa34eb60d6df to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
class Base{
private:
string value = "base";
public:
virtual string function(){ return value; }
};
class Derived: public Base{
private:
string othervalue = "derived";
public:
string function(){ return othervalue; }
};
int main(){
Base * b = new Base();
cout << b->function() << endl;
b = new Derived();
cout << b->function() << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment