I've just updated GCC from (I think) 4.5.6 to 4.6.1, under Windows, MinGW. Suddenly my NonInstantiable base class (from which you inherit with public virtual to prevent instantiation) refuses to work with the following and similar error messages:
#ifndef Frigo_Lang_NonInstantiable
#define Frigo_Lang_NonInstantiable
namespace Frigo
{
namespace Lang
{
/**
* Inherit from this class if you want to make a non-instantiable class. Most
* useful for static classes. It seems every inheritance combination
* (public/protected/private, non-virtual/virtual) shuts off instantiation in
* all subclasses as well.
**/
class NonInstantiable
{
private:
/* Private Classes */
/**
* A dummy class to prevent GCC warnings about virtual
* constructors/destructors and no friends
**/
class NonInstantiableDummy { };
/* Private Constructors */
/**
* Private constructor to prevent instantiation
**/
NonInstantiable() { }
/**
* Private destructor to prevent instantiation on the stack. Virtual to
* prevent GCC warnings
**/
virtual ~NonInstantiable() { }
/* Friends */
friend class NonInstantiableDummy;
};
}
}
#endif
Errors:
/code/Frigo/Util/Arrays:40:7: error: deleted function 'virtual Frigo::Util::Arrays::~Arrays()'
/code/Frigo/Lang/Object:37:11: error: overriding non-deleted function 'virtual Frigo::Lang::Object::~Object()'
/code/Frigo/Util/Arrays:40:7: error: 'virtual Frigo::Util::Arrays::~Arrays()' is implicitly deleted because the default definition would be ill-formed:
/code/Frigo/Lang/NonInstantiable:39:11: error: 'virtual Frigo::Lang::NonInstantiable::~NonInstantiable()' is private
/code/Frigo/Util/Arrays:40:7: error: within this context
/code/Frigo/Lang/NonInstantiable:39:11: error: 'virtual Frigo::Lang::NonInstantiable::~NonInstantiable()' is private
/code/Frigo/Util/Arrays:40:7: error: within this context
/code/Frigo/Util/Arrays:40:7: error: deleted function 'virtual Frigo::Util::Arrays::~Arrays()'
/code/Frigo/Lang/NonInstantiable:39:11: error: overriding non-deleted function 'virtual Frigo::Lang::NonInstantiable::~NonInstantiable()'
I suspect it is because I do not create any destructors, virtual or otherwise, in the child classes, and this somehow conflicts with the private virtual destructor of NonInstantiable, but I need confirmation. And a solution how to fix my NonInstantiable class to suppress these errors, but still work.
static
keyword to mark such classes, but IIRC it allows only static methods, it throws a fit when it sees a static variable. – Albric