R
Riley DeWiley
I am looking for a graceful way to declare a string const that is to be
visible across many files.
If I do this:
//----hdr.h
const char * sFoo = "foo";
//file.cpp
#include <hdr.h>
strcpy(string, sFoo);
//anotherfile.cpp
#include <hdr.h>
strcpy(string, sFoo);
The linker complains that sFoo is multiply defined.
I don't want to use a #define as it breaks type safety. I don't want to have
multiple copies of '
const char * sFoo = "foo";' littering my code.
What is the most compact and maintainable way to do this?
RDeW
visible across many files.
If I do this:
//----hdr.h
const char * sFoo = "foo";
//file.cpp
#include <hdr.h>
strcpy(string, sFoo);
//anotherfile.cpp
#include <hdr.h>
strcpy(string, sFoo);
The linker complains that sFoo is multiply defined.
I don't want to use a #define as it breaks type safety. I don't want to have
multiple copies of '
const char * sFoo = "foo";' littering my code.
What is the most compact and maintainable way to do this?
RDeW