Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!decwrl!uunet!brunix!sdm From: sdm@cs.brown.edu (Scott Meyers) Newsgroups: comp.lang.c++ Subject: Initializing Static Members of Template Classes Message-ID: <79635@brunix.UUCP> Date: 28 Jun 91 15:56:50 GMT Sender: news@brunix.UUCP Reply-To: sdm@cs.brown.edu (Scott Meyers) Organization: Brown University Department of Computer Science Lines: 50 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 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 const double Time::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."