C++ - How to get a const global object?

Armitage

Banned
Feb 23, 2001
8,086
0
0
I have a JulianDate class, and I want to define a constant gloabl instance of an object for a specific date. This particular date gets used in alot of calculations, so it'd be handy to have around, and to be sure that nobody can dick it up.

I can put this in the implementation file for the class:
//The epoch for the J2000 coordinate frame
JulianDate J2K("2000-01-01 12:00:00", "%Y-%m-%d %H:%M:%S");

And that works fine - I can declare it as a const extern wherever I need it in the code
extern const JulianDate J2K;

But I can also declare it as a non-const:
extern JulianDate J2K;

Is there any way to decalre this variable so that it can't be used as a non-const? If I make the declaration const:
const JulianDate J2K("2000-01-01 12:00:00", "%Y-%m-%d %H:%M:%S");

Then whenever I try to use it I get a compiler error "undefined reference to `J2K'"
Ideas?
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: AllGoodNamesAreTaken
Don't know which compiler you are using, but it works fine in Visual C++ 6.0.

Interesting - I'm using the gnu compilers