-
-
Save freetstar/4403847 to your computer and use it in GitHub Desktop.
c++virtual method
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
/* | |
* ===================================================================================== | |
* | |
* Filename: test.cpp | |
* | |
* Description: G | |
* | |
* Version: 1.0 | |
* Created: 12/29/2012 08:50:05 AM | |
* Revision: none | |
* Compiler: gcc | |
* | |
* Author: freetstar (http://www.freetstar.com), [email protected] | |
* Company: | |
* | |
* ===================================================================================== | |
*/ | |
#include <iostream> | |
using namespace std; | |
class A | |
{ | |
public: | |
virtual void foo(){cout<<"A::foo() is called"<<endl;} | |
}; | |
class B: public A | |
{ | |
public: | |
virtual void foo(){cout<<"B:foo() is called"<<endl;} | |
}; | |
int main(int argc, const char *argv[]) | |
{ | |
A * a = new B(); | |
a->foo(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment