Skip to content

Instantly share code, notes, and snippets.

@freetstar
Created December 29, 2012 01:36
Show Gist options
  • Save freetstar/4403847 to your computer and use it in GitHub Desktop.
Save freetstar/4403847 to your computer and use it in GitHub Desktop.
c++virtual method
/*
* =====================================================================================
*
* 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