TITLE: Global objects with const and static PROBLEM: srheintze@happy.uccs.edu I previously used the definition enum Boolean { FALSE, TRUE }; But this produced syntax errors when I used it this way: Boolean container::empty()const { return count() == 0; } So I abandoned enum in favor of the following contents of Boolean.h: [a] typedef int Boolean; const Boolean TRUE = 1; const Boolean FALSE = 0; This appears to work, but lately I have been thinking it should fail. Why don't I get errors when include Boolean.h in multiple modules of the same program? [b] RESPONSE: steve@taumet.com (Steve Clamage), 13 May 93 [a] Of course, because there is no implicit conversion from int (the type of a comparison result) to any enum type. [b] Because in C++ a const object at file scope is static unless declared extern. (This is a difference from C.) Each compilation unit gets its own static copy of TRUE and FALSE. In this simple case, however, the compiler will certainly optimize away the generation of an actual instance of TRUE and FALSE unless you take their addresses or generate a reference to them. BTW, when you use a boolean TRUE, be careful how you test against it. All non-zero values evaluate as true in a boolean context, but only the exact value 1 will compare equal to TRUE. It is possible for (expression != FALSE) and (expression != TRUE) both to be true.