Virtual function: Difference between revisions

Content deleted Content added
mNo edit summary
+most important statement
Line 110:
 
== Behaviour during construction and destruction ==
Languages differ in their behaviourbehavior while the [[Constructor (computer science)|constructor]] or [[Destructor (computer science)|destructor]] of an object is running. For this reason, calling virtual functions in base class constructors is fatal in C++ (and compilers or linker would not issue error nor warning according to the scope of the language), therefore being generally discouraged (softly speaking).
 
In C++, the "base" function is called. Specifically, the most derived function that is not more derived than the current constructor's class is called.<ref>{{cite web |title=Never Call Virtual Functions during Construction or Destruction |last=Meyers|first=Scott|date=June 6, 2005 |url=http://www.artima.com/cppsource/nevercall.html}}</ref> If that function is a pure function, then undefined behavior occurs.