|
From: Farzan H. <far...@ho...> - 2005-05-29 09:14:27
|
Hi,
Please help me with the following code. We have three files: a header fil=
e =20
and two
implementation files.
// Source of "header.h"
#ifndef HEADER_H
#define HEADER_H
int p;
#endif
--------------------------------
// Source of "main.cpp"
#include <cstdio>
#include "header.h"
int main()
{
printf("%i\n",p);
return 0;
}
--------------------------------
// Soruce of "func.cpp"
#include "header.h"
int func()
{
return p;
}
The compiler generates the error " multiple definition of 'p' ".
What is wrong with the code?
When the header file is included for the first time, the macro "HEADER_H"=
=20
is defined
but when the header file is included in the second implementation file,
"HEADER_H" can not be recognized in the second file and "p" is defined =20
once more!!
It seems macros have file scope.
Thanks,
--=20
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
|