So I've been messing around with namespaces,here's what I have:
1.h
namespace x{
void d();
float j;
int m();
}
When i compile that I get this:
'float x::j' : redefinition
I don't understand,what am I doing wrong?!
So I've been messing around with namespaces,here's what I have:
1.h
namespace x{
void d();
float j;
int m();
}
When i compile that I get this:
'float x::j' : redefinition
I don't understand,what am I doing wrong?!
Looks like the header is getting included more than once in a file. You need include guards or #pragma once
Include guards look like this:
#ifndef INCLUDED_1_H
#define INCLUDED_1_H
// contents of header file
#endif
Each header file needs a uniquely named #define when doing it the include guards way.
Also, the reason it didn't moan about d() or m() being redefined is because function declarations are implicitly extern (unless static). You could get away with no include guard (not recommended though) if you had
extern float j;
in the header and defined it as
float x::j;
in one and only one cpp file (presumably, 1.cpp).
And I hope the file name and variable names are just for illustration, otherwise, you're fired ;)