Slashdot is powered by your submissions, so send in your scoop

 



Forgot your password?
typodupeerror
×

Comment Re:It's been injecting its own bugs since cfront. (Score 1) 365

There is nothing dangerous about calling the derived class' own override when initializing / destroying member objects of that derived class. When member objects are being initialized, the object's "underpinning" (allocation, base instances, vtable) is fully initialized. And conversely, the underpinning is not dismantled before the members have been destroyed. Binding of calls to derived class' override into the base class' version, inside the derived class, would be confusing and it's not permitted by the standard.

Now, calling derived class' override within base's constructor would dangerous. Perhaps that's what you meant? Luckily, ever since the first edition of c++ standard in 1998*, compilers have been disallowed from making virtual calls inside the constructor (/destructor/member initializer). The version called is always the one in constructor's owning class (i.e. statically bound).

I don't think the bug you're describing exists in the c++ standard. It may exist in a compiler that doesn't conform to the standard, though.

* 12.7.3:

Member functions, including virtual functions (10.3), can be called during construction or destruction (12.6.2). When a virtual function is called directly or indirectly from a constructor (including from the mem-initializer for a data member) or from a destructor, and the object to which the call applies is the object under construction or destruction, the function called is the one defined in the constructor or destructor’s own class or in one of its bases, but not a function overriding it in a class derived from the constructor or destructor’s class, or overriding it in one of the other base classes of the most derived object (1.8). If the virtual function call uses an explicit class member access (5.2.5) and the object-expression refers to the object under construction or destruction but its type is neither the constructor or destructor’s own class or one of its bases, the result of the call is undefined

Slashdot Top Deals

Pascal is not a high-level language. -- Steven Feiner

Working...