Article ID: 129210
Article Last Modified on 10/17/2003
static const char *const str[2] = { "string1", "string2" };
This definition can be placed in a header file, and can be included in
multiple source files. However, there are implications for the size of the
program when you use this workaround. That is, a copy of the array and of
the strings will be in every module that includes the header file, whether
you use it or not. The sample code below shares this problem.
// Compile options needed: None
// Test.h
const char *const str[] = { "string1" , "string2" }; // error
// Module1.cpp
#include "test.h" // included test.h once in project.
#include <iostream.h>
void function1()
{
cout << "In Function1" << endl;
}
// Module2.cpp
#include "test.h" // included test.h twice in project
#include <iostream.h>
extern void function1();
void function2()
{
cout << "In Function2" << endl;
}
void main()
{
function1();
function2();
return;
}
Additional query words: 1.00 1.50 1.51 1.52 8.00 8.00c
Keywords: kbbug kbfix kbcodegen kbcpponly kbcompiler KB129210