sdm@cs.brown.edu (Scott Meyers) (06/28/91)
Suppose I want to create a set of classes for representing various units of time. One way to do it would be to choose some canonical time unit, say seconds, and then define all the classes the same way, each one having a different conversion factor between itself and the canonical unit: class Second { private: static const double conversionFactor; ... }; const double Second::conversionFactor = 1; class Minute { private: static const double conversionFactor; ... }; const double Minute::conversionFactor = 1.0/60.0; Clearly, this is a case for templates: template <double conversion> class Time { private: static const double conversionFactor; ... }; typedef Time<1> Second; typedef Time<1.0/60.0> Minute; typedef Time<1000> MilliSecond; Now for my question: how do we initialize the static member of the template class? Can we write this? template <double conversion> const double Time<conversion>::converstionFactor = conversion; The ARM seems to say that templates are only for classes or functions, not for individual objects. So how can we do this? Scott ------------------------------------------------------------------------------- What do you say to a convicted felon in Providence? "Hello, Mr. Mayor."