Y
Yanxiong
I have three files: file1.h, file1.cpp, test_main.cpp, and the source
code as follow:
file.h
#ifndef _FILE1_H_
#define _FILE1_H_
#include <cstdio>
/*********************************
Here is the problem, if I use const char *STR = "Test const char *";
the Compiler tell "fatal error LNK1169: one or more multiply defined
symbols found.", if I use static const char *STR = "Test const char
*"; or const char STR[ ] = "Test const char *"; it will be OK. I don't
know why??? If you know,please tell me,thanks very much.
*****************************/
const char *STR = "Test const char *";
void print(const char *str);
#endif
file.cpp
#include "file1.h"
void print(const char *str)
{
printf("%s\n", str);
}
test_main.cpp
#include "file1.h"
int main()
{
print(STR);
return 0;
}
code as follow:
file.h
#ifndef _FILE1_H_
#define _FILE1_H_
#include <cstdio>
/*********************************
Here is the problem, if I use const char *STR = "Test const char *";
the Compiler tell "fatal error LNK1169: one or more multiply defined
symbols found.", if I use static const char *STR = "Test const char
*"; or const char STR[ ] = "Test const char *"; it will be OK. I don't
know why??? If you know,please tell me,thanks very much.
*****************************/
const char *STR = "Test const char *";
void print(const char *str);
#endif
file.cpp
#include "file1.h"
void print(const char *str)
{
printf("%s\n", str);
}
test_main.cpp
#include "file1.h"
int main()
{
print(STR);
return 0;
}