To get different definitions for a class depending on some condition, put the dependency calculation in a template argument.
// primary template, no default constructor unless Something is true
template< typename T, bool has_default_ctr = Something > class MyClass {
// as you had it, with no default constructor
};
// you want MyClass<T,true> to be just like MyClass<T,false>
// but with a default constructor:
template< typename T > class MyClass<T,true> : public MyClass<T,false> {
MyClass() : MyClass<T,false>(/* chosen constructor args */) { etc; }
using MyClass<T,false>::MyClass<T,false>;
};
if you don't have C++11 you can't use the using
constructor inheritance and you'll have to redeclare all its constructors and forward their arguments along to the base class.
This is fingers-to-keyboard, I don't have a compiler handy atm so minor syntax goofs are somewhat likely.
enable_if
and a constructor with an argument with a default value? – Coccyx