rahulsin...@gmail.com wrote: > I was trying to compile chromium today on Linux and I got this error. > This error occurred because of -Werror CFLAG set in the Makefile. I > remedied by writing a one-liner to delete all occurrences of -Werror > from CFLAGS in all Makefiles.
I happen to find this warning very useful, just as I find our policy to make warnings hard errors in our own code helpful. > Base *b = new Sub(); > delete b; > > To the best of my knowledge, if Base is the class which defines > virtual methods but non-virtual destructor, delete can cause a memory > leak if Sub happens to be taking more memory than Base. Strictly speaking, the problem isn't precisely that a leak will occur if Sub is larger than Base. The real problem is that Sub::~Sub won't run unless Base declares a virtual destructor. > I think that > the destructor for a class with virtual methods has either to be > "public virtual" or "protected non-virtual" for the proper freeing of > memory. > > Would someone help me clarify this? >From our style guide: http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Inheritance#Inheritance "Make your destructor virtual if necessary. If your class has virtual methods, its destructor should be virtual." As Evan points out, there are some cases when it's not absolutely necessary to have a base or interface class declare a virtual destructor. Mark -- Chromium Developers mailing list: chromium-dev@googlegroups.com View archives, change email options, or unsubscribe: http://groups.google.com/group/chromium-dev