Topic: static const member variables: a proposal?


Author: moudgill@cs.cornell.edu ( Mayan Moudgill)
Date: Tue, 15 Feb 1994 21:04:53 GMT
Raw View
Consider the following situation:
 class A {
 public:
     static const double scale;

            double val;

 inline A(double d) { val = d/scale };
 };

 static const double A::scale = 3.0;

 main()
 {
 A  a = 1.0000;
 }

Hopefully, the division will get optimized away by the compiler.....


Now, unfortunately, there can be exactly one instance of the declaration
of the const. Which means that, typically, we'd put the class declaration
in a .H file, and the const definition in a .C file somewhere else....
and the optimization is no longer possible....
{ And yes, I know the enum trick for ints....GAG!}

So: proposal: *PLEASE* treat static const just like all other consts,
in that they can be defined multiple times, as long as they are defined
identically.

:)
Mayan