c++ - Virtual function is called after Vtable is deleted -


why giving segmentation fault? seems virtual table deleted , user tries call function looks absurd.

class base {     char *basep;     public:      // deep copy exist in copy constructor      virtual char * fun()     {         cout << "fun drive";         return basep;     }     virtual ~base()     {         if(basep) { delete basep; }         char *temp = fun();     } };  class derive : public base {     char *derived;     public:     // deep copy exist in copy constructor of derived     virtual char *fun()     {         cout << "fun drive";         return derived;     }     ~derive()     {         if(derived) { delete derived; }     } };  int main() {     base *obj = new base;     delete obj; } 


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -