You're trying to create a std::numeric_limits
that inherits from std::numeric_limits
-- but by the time you get to the public numeric_limits...
part, you've already declared your own template (that's still incomplete) that's already named numeric_limits
, so it's trying to inherit from itself instead of the existing std::numeric_limits
.
std::numeric_limits
isn't intended as a base class, and doesn't provide any virtual functions, so inheriting from it isn't useful anyway. To make numeric_limits
handle your particular class correctly, you want to define a specialization of numeric_limits for that type:
#include <limits> // get base template definition + standard specializations
namespace std {
template<> // define your specialization
class numeric_limits<MyType> {
// ...
};
}
Note that this is one of the only cases where you're allowed to add something to the std
namespace -- adding a new specialization of an existing template over a user defined type.