多态 C1
1 class base { 2 public: 3 virtual void test1() { std::cout << "base::test1"<< std::endl; } 4 void test2(){ std::cout << "base::test2"; }
fun()
{
test1();
test2();
}
5 }; 6 7 class derive{ 8 public: 9 void test1(){ std::cout << "derive::test1" << std::endl;} 10 void test2(){ std::cout << "derive::test2" << std::endl;} 11 };
int main()
{
derive d;
d.fun();
}