Is this the proper way to use a static const variable? In my top level class (Shape)
#ifndef SHAPE_H
#define SHAPE_H
class Shape
{
public:
static cons
For primitive data types (like int, double but not char[]) you may also define the constant within the class definition within the header file, e.g.:
class Shape
{
public:
static const double pi = 3.14159265;
private:
double originX;
double originY;
};
This will allow better compiler optimisation.
Edit: As Dennis pointed out below this is only allowed for integral types and not for double or float data types (however some compilers will allow it).