Re: [Flightgear-devel] compile warning
Curtis L. Olson writes: For the C++ experts, I'm starting to see a lot of these sorts of warnings? Other than trying to avoid and clean up warning litter, is this dangerous? What's the best fix for this? ../../src/Main/globals.hxx:321: warning: `class FGGlobals' has virtual functions but non-virtual destructor Ah you must have upgraded to gcc 3.2 :-) My take is that this is just a warning but like most warnings emitted by the compiler has a sound basis and is reason for concern In this specific case I question the need for the three functions being declared virtual but to clean things up just ... declare the destructor virtual and un inline it Norman ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
Re: [Flightgear-devel] compile warning
Norman Vine writes: Curtis L. Olson writes: For the C++ experts, I'm starting to see a lot of these sorts of warnings? Other than trying to avoid and clean up warning litter, is this dangerous? What's the best fix for this? ../../src/Main/globals.hxx:321: warning: `class FGGlobals' has virtual functions but non-virtual destructor Ah you must have upgraded to gcc 3.2 :-) No actually this is due to recent code changes I believe. My take is that this is just a warning but like most warnings emitted by the compiler has a sound basis and is reason for concern In this specific case I question the need for the three functions being declared virtual but to clean things up just ... declare the destructor virtual and un inline it Sound ok David? I think this is your code. Regards, Curt. -- Curtis Olson IVLab / HumanFIRST Program FlightGear Project Twin Cities[EMAIL PROTECTED] [EMAIL PROTECTED] Minnesota http://www.menet.umn.edu/~curt http://www.flightgear.org ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
Re: [Flightgear-devel] compile warning
Curtis L. Olson wrote: For the C++ experts, I'm starting to see a lot of these sorts of warnings? Other than trying to avoid and clean up warning litter, is this dangerous? What's the best fix for this? warning: `class FGGlobals' has virtual functions but non-virtual destructor If you have virtual functions, then the assumption has to be that you will be using the class polymorphically. If you are using it polymorphically, you might be expected to delete objects using a pointer to the base class instead of the real class. If you do this with a non-virtual destructor, bad things ensue. :) More tersely, if you have: class SubClass : public ParentClass { ... }; ParentClass * p = new SubClass(...); delete p; If ParentClass has a *non* virtual destructor, then this code will call only ParentClass's destructor. The SubClass destructor will never be invoked on this SubClass object, and you will leak memory, or resources, or leave dangling pointers, or worse. A virtual destructor works by first calling the SubClass destructor, and then automatically chaining in calls to the superclass destructors in order to make sure that everything is cleaned up. So basically, put a virtual in front of the destructor declaration for any classes whose subclasses can be deleted through pointers to the base class. It's easy and safe and the Right Thing. The compiler warning doesn't necessarily indicate a problem; but there really aren't any downsides do heeding it anyway. Andy -- Andrew J. RossNextBus Information Systems Senior Software Engineer Emeryville, CA [EMAIL PROTECTED] http://www.nextbus.com Men go crazy in conflagrations. They only get better one by one. - Sting (misquoted) ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
re: [Flightgear-devel] compile warning
Curtis L. Olson writes: For the C++ experts, I'm starting to see a lot of these sorts of warnings? Other than trying to avoid and clean up warning litter, is this dangerous? What's the best fix for this? ../../src/Main/globals.hxx:321: warning: `class FGGlobals' has virtual functions but non-virtual destructor My fault -- I didn't add a virtual destructor. Always, always, always define a virtual destructor to avoid memory leeks. All the best, David -- David Megginson, [EMAIL PROTECTED], http://www.megginson.com/ ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
Re: [Flightgear-devel] compile warning
Curtis L. Olson writes: Sound ok David? I think this is your code. Globals is no one's. You (Curt) started it, and I've hacked it a lot. I actually plan to take a hatchet to it soon and cut out a lot of deadwood, and I'll queue up this change as well. I don't want to make it alone, because every time I touch globals.hxx I force everyone to rebuild most of FlightGear. All the best, David -- David Megginson, [EMAIL PROTECTED], http://www.megginson.com/ ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
Re: [Flightgear-devel] compile warning
On Thu, 16 Jan 2003 15:00:06 -0600 Curtis L. Olson [EMAIL PROTECTED] wrote: For the C++ experts, I'm starting to see a lot of these sorts of warnings? Other than trying to avoid and clean up warning litter, is this dangerous? What's the best fix for this? ../../src/Main/globals.hxx:321: warning: `class FGGlobals' has virtual functions but non-virtual destructor Is FGGlobals an abstract class (i.e. does it have pure virtual functions)? To the best of my knowledge: If your base class FGGlobals has virtual functions, one assumes you will derive from it. One also assumes that there will need to be cleanup done when the object (possibly a class derived from FGGlobals) is destroyed. You may have a pointer that points to an instance of FGGlobals (if instantiable) or a class derived from it (implementing polymorphism). There may be several different derivative classes of FGGlobals, but you'll use a pointer to an FGGlobal type to refer to it. Still, each derived class may have its own way of destruction, so the base class has to have a virtual destructor (which might have some kind if default destruction process coded for it) and perhaps a derived class destructor that overrides the base class destructor. Anyhow, that's my best guess. Jon ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel
Re: [Flightgear-devel] compile warning
On Thu, 16 Jan 2003 15:00:06 -0600 Curtis L. Olson [EMAIL PROTECTED] wrote: For the C++ experts, I'm starting to see a lot of these sorts of warnings? Other than trying to avoid and clean up warning litter, is this dangerous? What's the best fix for this? By the way, the fix is to declare the destructor virtual, in my experience. ___ Flightgear-devel mailing list [EMAIL PROTECTED] http://mail.flightgear.org/mailman/listinfo/flightgear-devel