14.5.2p5
Because the explicit template argument list follows the function template name, and because conversion member function templates and constructor member function templates are called without using a function name, there is no way to provide an explicit template argument list for these function templates.
All template parameters for constructors should be deducted:
template <typename T> Seconds(T); would work template <typename T> Seconds( ); would not
I am not sure I understand. The code compiles fine. In my case, the generic is not for the typename, rather for the value of num and den. I took my inspiration from std::ratio. Is it fundamentally wrong to have a constructor like Seconds' ? Why does it work in std::ratio's case and not this one?
// not very useful; might as well make num and den run-time entities
struct seconds
{
seconds( double v = 0 ) : value(v) {}
template < int num, int den > seconds& set( double v )
{
value = v * num / den ;
return *this ;
}
template < int num, int den > static seconds init( long v )
{ seconds s ; return s.set<num,den>(v) ; }
// ...
double value ;
};
// could be useful; along the lines of std::ratio
template < int num, int den > struct seconds_a_la_ratio
{
seconds_a_la_ratio( double v = 0 ) : value( v*num/den ) {}
double value ;
};
int main()
{
seconds s = seconds::init<1,1000>(30);
seconds_a_la_ratio<1,1000> s2(30) ;
}