
Sohail Somani wrote:
On Tue, 01 Apr 2008 13:48:03 -0400, Edward Diener wrote:
A global enumerated value called ERROR is not a good idea.
In C++, a global anything is not a good idea especially if you use other libraries. At the least, you should be doing C-style namespacing, i.e., product_ERROR, if you are into that sort of thing.
You mean like this: #include <boost/date_time.hpp> // or <windows.h> namespace X { class Y { typedef enum {OK=1, ERROR} myEnumT; }; } // namespace X int main(int argc, char* argv[]) { return 0; } The issue is not that the ERROR was globally enumerated. The issue is that ERROR is #defined in one of the headers that is included by windows.h. This is, of course, the fault of the windows headers for not respecting the set of symbols that it is allowed to define, but it is surprising to have otherwise valid code break by the inclusion of a boost header. Here is another example that is even harder to track down: ---8<--- Z.h ---8<--- #ifndef Z_incl #define Z_incl class Z { public: int GetMessage() const { return val; } private: int val; }; #endif ---8<--- main.cpp ---8<--- #include "Z.h" #include <boost/date_time.hpp> // or <windows.h> void foo() { Z z; z.GetMessage(); // error: GetMessageA is not a member of Z } ---8<--- ---8<--- David