C
chat
Hi, every body.
I have 3 files like this:
--------------------------------------------------------
file name : header.h
#ifndef TEST_H
#define TEST_H
int a=1;
double b=0.5;
void fn1();
#endif
---------------------------------------------------------
file name : file1.cpp
#include<iostream>
#include "header.h"
using namespace std;
void fn1()
{
cout<<a;
}
---------------------------------------------------------
file name : file2.cpp
#include<iostream>
#include "header.h"
using namespace std;
void main()
{
fn1();
}
----------------------------------------------------------
I use vc++ 6.0 compile all the files and no error occur. The problem
occur when I build program.
The error message are:
file2.obj : error LNK2005: "double b" (?b@@3NA) already defined in
file1.obj
file2.obj : error LNK2005: "int a" (?a@@3HA) already defined in
file1.obj
Debug/test.exe : fatal error LNK1169: one or more multiply defined
symbols found
What is the mistake? Why are variable a,b multiple defined since I use
compiler directive to assure the multiple include header file?
Thank you in advance
Chat
I have 3 files like this:
--------------------------------------------------------
file name : header.h
#ifndef TEST_H
#define TEST_H
int a=1;
double b=0.5;
void fn1();
#endif
---------------------------------------------------------
file name : file1.cpp
#include<iostream>
#include "header.h"
using namespace std;
void fn1()
{
cout<<a;
}
---------------------------------------------------------
file name : file2.cpp
#include<iostream>
#include "header.h"
using namespace std;
void main()
{
fn1();
}
----------------------------------------------------------
I use vc++ 6.0 compile all the files and no error occur. The problem
occur when I build program.
The error message are:
file2.obj : error LNK2005: "double b" (?b@@3NA) already defined in
file1.obj
file2.obj : error LNK2005: "int a" (?a@@3HA) already defined in
file1.obj
Debug/test.exe : fatal error LNK1169: one or more multiply defined
symbols found
What is the mistake? Why are variable a,b multiple defined since I use
compiler directive to assure the multiple include header file?
Thank you in advance
Chat