C++多态
有一个注意要点,必须用指针,不能用A a = B()的形式。
#include "stdafx.h" #include "Base.h" #include "Class2.h" int _tmain(int argc, _TCHAR* argv[]) { Base* base = new Class2(); base->Run(); //Base Class Run Function will print "Base" //Class2 Class Run Function will print "Class2" //Execute program print "Class2" return 0; }