Created
February 6, 2015 12:58
-
-
Save alexshires/0cbef200036778d8efe7 to your computer and use it in GitHub Desktop.
virtual functions
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> | |
class A { | |
public: | |
virtual double f () = 0 ; | |
double g() { return f() ; } | |
} ; | |
class B : public A { | |
public: | |
double f() { return 1 ; } | |
} ; | |
int main(int argc, char *argv[]) | |
{ | |
B b ; | |
std::cout << b.g() << std::endl ; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment