0
virtual function
class super { public: virtual~super(){cout<<1;} }; class sub: public super { public: ~sub(){cout << 2;} }; int main(){ super*ptr = new sub delete ptr; } // outputs 21 Why does the 1 get outputted? I believe that the pointer points to the sub class's sub function, which prints out 2. But I don't understand what allows the base class's super function to be expressed... Is there something I should know about virtual functions?
1 ответ