common.h
extern char *gCert[] = {"Abdul", "Gotez", "Arhaim", "Erhan"};
template.h
...
template.cpp
#include "common.h"
char *gCert[];
void generateTemplate()
{
for (int i = 0; i < 4; ++i)
{
/* code */
printf("gCert[i]\n");
}
}
main.h
...
main.cpp
#include "common.h"
char *gCert[];
void printRandomCert()
{
srand(GetTickCount());
int nSeed = rand() % 4;
for (int i = 0; i < 4; ++i)
{
/* code */
printf("gCert[(nSeed + i) % 4]\n");
}
}
As you see, I'd like to use gCert
in multiple cpp files, but cannot use like this.
I got an error below
error LNK2005: "char * * gCert" (?gCert@@3PAPEADA) already defined in template.obj
Is it impossible to use global variable like above? If possible, please share your answers.
Environment: Windows 10 x64, VisualStudio 2017 C++ Win32 Application & DLL