c++ - Calling virtual function of derived class from base class constructor? -


i´m trying accomplish same described in previous question:

virtual function call base class

but, real question is:

what if f() constructor in base class? g() called? don´t know if doing wrong, in program seems opposite.

taking same variables previous question, code shows such

behavior this:

class base  {         base(){g();};      virtual void g(){//do base related code;}  };    class derived : public base  {         derived(){};      virtual void g(){//do derived related code};  };    int main()  {      derived newderived;      return 0;    } 

update:

thanx naveen.

he provided me page contains related information topic.

i´ll let know link here:

parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.6

even though it's virtual function, base's version called since derived class isn't constructed yet. base class constructor called before derived class constructor, if derived virtual function called, incompletely-initialized instance - possible (probably) recipe disaster.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -