c++ - extern const std::string not initialized under iOS, works fine on Windows -


i have configurations.h , configurations.cpp define constant string values used everywhere in cross-platform application. in file use of these values create other constant strings. this:

const std::string shader_source_head_es = configurations::default_shader_version_es + shader_source_line_break + "precision mediump float" + shader_source_line_ending; 

this works fine on windows , worked on ios before changed "extern const" in configurations.h , did declaration in cpp-file.

now on ios configurations::default_shader_version_es empty. configuration.h of course included first, constants should exist (and on windows). have functions use constants (in same file const std::string shader_source_head_es) , there work.

what wrong here? thank guys :-)

sounds it's order of initialization issue. cleaner approach use functions provide access strings. in functions, make variable static , initialize them appropriately.

for example, instead of using:

extern const int myvar; 

in .h file and

const int myvar = 20; 

in .cpp file, use:

extern int getmyvar(); 

in .h file and

int getmyvar() {    static const int myvar= 20;    return myvar; } 

in .cpp file.


Comments