Created
March 19, 2015 00:48
-
-
Save lettergram/fc03d870fa34eb60d6df to your computer and use it in GitHub Desktop.
This file contains 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> | |
#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