include <iostream>
using namespace std;
class Base{
public:
virtual void virtualFoo1(){
cout << "Base::virtualFoo1 called" << endl;
// Foo1();
}
virtual void virtualFoo2(){ cout << "Base::virtualFoo2 called" << endl; }
void Foo1(){
cout << "Base::Foo1 called " << endl;
virtualFoo2();
Foo2();
}
void Foo2(){
cout << "Base::Foo2 called " << endl;
}
};
class Derived : public Base{
public:
virtual void virtualFoo1(){
cout << "Derived::virtualFoo1 called" << endl;
Foo1();
}
virtual void virtualFoo2(){
cout << "Derived::virtualFoo2 called" << endl;
Foo2();
}
void Foo1(){
cout << "Derived::Foo1 called " << endl;
virtualFoo2();
}
void Foo2(){
cout << "Derived::Foo2 called " << endl;
}
};
int main(){
Base * pb = new Derived;
//Base * pb = new Base;
pb->virtualFoo1();
cout <<"== == == == == == ==" << endl;
pb->Foo1();
system("pause");
}
网友评论