On Fri, Oct 30, 2009 at 3:54 PM, Jeremy Orlow <jor...@chromium.org> wrote: > On Fri, Oct 30, 2009 at 3:46 PM, Scott Hess <sh...@chromium.org> wrote: >> Just to be clear for those of us who are wobbly on C++, this is >> because during the constructor or destructor, your object is of the >> class in question, NOT of the class it will finally be, because in the >> constructor the subclass has not been constructed, yet, and in the >> destructor the subclass was already destructed. So calling to the >> subclass virtual implementation would be bad. >> >> Scott Meyers says: http://www.artima.com/cppsource/nevercall.html >> >> Is there any way we could modify an object to assert that it can't >> happen in development? Like scoped_vtable_killer declared in the >> constructor and destructor which makes calling a virtual method on >> that object fatal? > > Or is there any sort of built in compiler warning that we could turn on? I > did a bit of searching and was really surprised that I couldn't find any > mention of such a thing.
It would have to be a really smart compiler, because you could call a function which calls another object's function which calls back to a virtual in your object. That's why I suggested a way to make vtable references fatal, so at least when doing development you could get a notification (and not check it in). -scott --~--~---------~--~----~------------~-------~--~----~ Chromium Developers mailing list: chromium-dev@googlegroups.com View archives, change email options, or unsubscribe: http://groups.google.com/group/chromium-dev -~----------~----~----~----~------~----~------~--~---