Copy Code code as follows:
#include <iostream>
Class base{
Public
Base ()
{
std::cout<<std::endl;
std::cout<< "Base constructor" <<std::endl;
Func1 ();
std::cout<<std::endl;
}
Virtual ~base ()
{
std::cout<<std::endl;
std::cout<< "Base Distructor" <<std::endl;
Func1 ();
std::cout<<std::endl;
}
virtual void func1 ()
{
std::cout<< "Base virtural func1" <<std::endl;
}
void Func2 ()
{
std::cout<< "Base member Func2" <<std::endl;
Func1 ();
std::cout<<std::endl;
}
};
Class Derived:public base{
Public
Derived ()
{
std::cout<<std::endl;
std::cout<< "derived constructor" <<std::endl;
Func1 ();
std::cout<<std::endl;
}
Virtual ~derived ()
{
std::cout<<std::endl;
std::cout<< "Derived Distructor" <<std::endl;
Func1 ();
std::cout<<std::endl;
}
virtual void func1 ()
{
std::cout<< "derived virtual func1" <<std::endl;
}
};
int main ()
{
Base *point = new derived ();
POINT->FUNC2 ();
Delete point;
return 0;
}
There will be such an output
Even if FUNC1 is a virtual function, in the base class and derived constructors and destructors, they call the func1 within their own classes.
And in the ordinary member function Func2 call FUNC1, will walk the virtual function flow.