Put only function prototypes and extern object declarations in header files, such as
// A.h file
extern void foo();
extern int f1;
Now, in one and only one *.cpp file you have to declare the same without theextern keyword.
// A.cpp file
#include "A.h"
int f1 = 0;
void foo()
{
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>How to do this way???
You don't! Function implementations can not be put in header files for the reason you have already discovered -- duplicate definition errors.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343