c++ - How to create a string table -


strangely there's no online documentation on subject. have application hard coded strings ui , various other things scattered through source. i'm attempting round @ least of them because number of them need change depending on platform application compiled for.

i used second example here (copied below reference) it's light on details of how should work. appears reinitialized in project_strings.cpp , code never called.

// in project_strings.h namespace myprojectstrings { const char *password; ... }  // project_strings.cpp strings #include "project_strings.h" namespace myprojectstrings { const char *password = "password:"; ... }  // random user needs string #include "project_strings.h" std::string password(myprojectstrings::password); 

can explain or tell me terrible idea , should else?

the example link declaring const char*s in namespace in header file , defining them in .cpp file. syntax used incorrect c++ though - declarations in header file should extern const char* rather const char* const values default internal linkage in c++.

most c++ compiler/linker toolchains place strings 1 translation unit (project_strings.cpp) in read data segment of resulting executable.

this reasonable, simple approach handling static strings although want bit more dynamic / sophisticated if need handle localization or other complexities.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -