class Base {
public:
Base() { std::cout << "Base\n"; }
~Base() { std::cout << "~~Base\n"; }
public:
virtual void print() { std::cout << "Base print\n"; }
};
class Baby : public Base {
public:
Baby() { std::cout << "Baby\n"; print(); }
~Baby() { std::cout << "~~Baby\n"; }
public:
void print() override { std::cout << "Baby print\n"; }
};
int main()
{
Baby b;
return 0;
}
输出:
网友评论