defining a string constant
-
I have a constants.h file that I would like to use to store constants and such. When I include the file in a class in my project I keep getting Link Error:2005: "already defined in" errors when I try to declare a string constant in the constant.h file. How do I create global string constants that I can use througout my app? // constants.h: defines constants to be used througout application. // ////////////////////////////////////////////////////////////////////// #if !defined(APP_CONSTANTS_0209051212) #define APP_CONSTANTS_0209051212 //no problems here const APP_PATH_STRING_LENGTH = 255; //link errors when using these char* app_data_path = "data\\"; char* app_charts_path = "c:\\CHARTS\\"; #endif // !defined(APP_CONSTANTS_0209051212) Kevin Shaffer kshaff03@msn.com
-
I have a constants.h file that I would like to use to store constants and such. When I include the file in a class in my project I keep getting Link Error:2005: "already defined in" errors when I try to declare a string constant in the constant.h file. How do I create global string constants that I can use througout my app? // constants.h: defines constants to be used througout application. // ////////////////////////////////////////////////////////////////////// #if !defined(APP_CONSTANTS_0209051212) #define APP_CONSTANTS_0209051212 //no problems here const APP_PATH_STRING_LENGTH = 255; //link errors when using these char* app_data_path = "data\\"; char* app_charts_path = "c:\\CHARTS\\"; #endif // !defined(APP_CONSTANTS_0209051212) Kevin Shaffer kshaff03@msn.com
I made the strings static, which appears to have solved my problem. Is this the best way to handled such a problem? char* app_data_path = "data\\"; char* app_charts_path = "c:\\CHARTS\\"; to: static char* app_data_path = "data\\"; static char* app_charts_path = "c:\\CHARTS\\"; Kevin Shaffer kshaff03@msn.com
-
I made the strings static, which appears to have solved my problem. Is this the best way to handled such a problem? char* app_data_path = "data\\"; char* app_charts_path = "c:\\CHARTS\\"; to: static char* app_data_path = "data\\"; static char* app_charts_path = "c:\\CHARTS\\"; Kevin Shaffer kshaff03@msn.com
kshaff03 wrote: Is this the best way to handled such a problem? nope. the best way is like this: foo.cpp: #include "foo.h" const char* app_data_path = "data\\"; const char* app_charts_path = "c:\\CHARTS\\"; foo.h extern const char* app_data_path; extern const char* app_charts_path; making them static just means that every .CPP will get its own private copy of the strings. Image Toolkits | Image Processing | Cleek
-
kshaff03 wrote: Is this the best way to handled such a problem? nope. the best way is like this: foo.cpp: #include "foo.h" const char* app_data_path = "data\\"; const char* app_charts_path = "c:\\CHARTS\\"; foo.h extern const char* app_data_path; extern const char* app_charts_path; making them static just means that every .CPP will get its own private copy of the strings. Image Toolkits | Image Processing | Cleek
Thanks Chris, As usual, your the best. -Kevin Kevin Shaffer kshaff03@msn.com