Looks like the static initialization order fiasco.
If you define two static variables in different translation units (.cpp files) you can not be sure in what order they will be initialized. For you it looks like c is initialized before Rgb::colGreen.
// this is my rgb.h file.
// note the GL bits come from openGL glut library
//
// the colours are all defined in rgb.cpp like this.
// const Rgb Rgb::colGreen(0,1.0,0) ;
It doesn't matter if you access the static objects through an instance or through the class name. It's still the same objects so it gives you the same result.
I think Peter8u7 is right. To test this, try moving const Rgb c[3] = { Rgb::colRed, Rgb::colGreen, Rgb::colYellow }; inside main() to force it to initialize after static/global data. If this is indeed the problem then change Rgb::colred etc to be constexpr.
normally a static const member attribute is initialized in the class definition.
like that :
static const int NUM = 5;
except probably for const pointers , but I never put them const . If a static member is not const , then it must be initialized outside the class scope (like in a cpp file).
The thing is that it is not a primitive type and it is a RGB so the compiler tries to look at the class definition but it was not defined yet since the compiler did not see the }; My advise would be to remove the static and initialize them all in the list initializer since they are const.
Now I know global initialization needs to be done in main.
It doesn't need to be done in main(). The problem is what Peter87 pointed out: If you have two globals in two different C++ files then you don't know which one gets initialized first. This means that if one is initialized from the value of the other, then the results are undefined:
file1.cpp: int a = 9;
file2.cpp:
1 2
externint a;
int b = a;
Here b is initialized from a, but it's possible that b is initialized before a, so it might get zero, or (unlikely) some other value.