I
Ian Collins
I've never had cause to try this before, but is it possible to have a
template default constructor?
I wish to pass the type of a singleton to a class and use the static
methods of that singleton object in the class, for example:
template <typename Item>
bool getItemValue() {
return Item::getValue();
}
struct Item { static bool getValue(); };
struct X
{
typedef bool (*GetFn)();
const GetFn getFn;
template <typename T> X( const T& )
: getFn( getItemValue<T> ) {}
};
works, but requires a public default constructor for T.
template default constructor?
I wish to pass the type of a singleton to a class and use the static
methods of that singleton object in the class, for example:
template <typename Item>
bool getItemValue() {
return Item::getValue();
}
struct Item { static bool getValue(); };
struct X
{
typedef bool (*GetFn)();
const GetFn getFn;
template <typename T> X( const T& )
: getFn( getItemValue<T> ) {}
};
works, but requires a public default constructor for T.