compiler errors - C++: Filescope constants with same name are breaking one definition rule? -
i have 2 constants in 2 different .cpp files, both named const char const * texture_filename = "...";
one in a.cpp , other in b.cpp, @ file scope, , neither file includes other or should see 1 another, vs2010 generates linker error:
a.obj : error lnk2005: "char const * const texture_filename" (?texture_filename@@3pbdb) defined in b.obj
what doing wrong here, , how might fix without needing rename either constant?
what doing wrong here, , how might fix without needing rename either constant?
you defining 2 objects named texture_filename. that's problem.
there more 1 ways fix problem. simplest fix make them static in file scope.
static const char * texture_filename = "..."; update, in response op's comment
texture_filename not const object. happens point c style string const. can modify texture_filename elsewhere in file using:
texture_filename = <some other c style string>; to make texture_filename const, you'll need use:
// both pointer , points const. const char * const texture_filename = "...";
Comments
Post a Comment