0

I have this:

a.h:

class a
{
}
void func(){} //some golobal function

b.h:

include "a.h"
class b : public a
{
}

b.cpp:

#include "b.h"

I get the error:

error LNK1169: one or more multiply defined symbols found

I think I get the error because global function defined twice. I try to put extern before the function but is doesnt work. I use also #ifndef.. and I still get error. How can solve this problem?

Biffen
  • 6,249
  • 6
  • 28
  • 36
user11001
  • 372
  • 3
  • 14

1 Answers1

3

You have either only to declare the function in header a.h and define it in some cpp module or define it as an inline function. For example

inline void func(){} 

Otherwise the function will be defined as many times as there are cpp modules that include either header a.h or b.h.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335