Re: Problem with include header file



chat wrote:

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;
}
.... snip ...

What is the mistake? Why are variable a,b multiple defined since
I use compiler directive to assure the multiple include header file?

You have two fundamental problems. First you are declaring data
objects in header files, which is a no-no. Second, you are using
C++, which is off-topic here. We deal with C.

The purpose of headers is to export connections to another source
file.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
Also see <http://www.safalra.com/special/googlegroupsreply/>


.



Relevant Pages