J
jessica_boxer
I want a standard list of strings, which I want to implement in a
header as:
// Approach 1 in .h
namespace StdNames
{
const char* name1 = "Name1";
const char* name2 = "Name2";
// etc
}
If I put this in the header will it allocate space for name1 and name2
everywhere I include the header (meaning I should have a corresponding
cpp file that actually does the assignments, and declars the above as
extern) or does it treat these as logical constants? Is Approach 1
above, or apporach 2 more appropriate?
// Approach 2 in .h
namespace StdNames
{
extern const char* name1;
extern const char* name2;
// etc
}
// And in the .cpp file
#include "StdNames.h"
namespace StdNames
{
const char* name1 = "Name1";
const char* name2 = "Name2";
// etc
}
header as:
// Approach 1 in .h
namespace StdNames
{
const char* name1 = "Name1";
const char* name2 = "Name2";
// etc
}
If I put this in the header will it allocate space for name1 and name2
everywhere I include the header (meaning I should have a corresponding
cpp file that actually does the assignments, and declars the above as
extern) or does it treat these as logical constants? Is Approach 1
above, or apporach 2 more appropriate?
// Approach 2 in .h
namespace StdNames
{
extern const char* name1;
extern const char* name2;
// etc
}
// And in the .cpp file
#include "StdNames.h"
namespace StdNames
{
const char* name1 = "Name1";
const char* name2 = "Name2";
// etc
}