If I define a namespace
in multiple headers which contains declaration of function, class/struct definitions' interfaces then in the source files should I define those names inside the namespace itself or outside of it? e.g:
// file.h
namespace mylibNS{
void func();
struct Adder{
int operator()(int const&, int const&) const;
};
}
// file.cpp
#include "file.h"
void mylibNS::func(){}
int mylibNS::Adder::operator()(int const& x, int const& y) const{
return + y;
}
Or should I do it this way:
// file.cpp
#include "file.h"
namespace myibNS{
void func(){}
int Adder::operator()(int const& x, int const& y) const{ // this doesn't compile
return + y;
}
}
What is the difference between the two versions and which one should I use? In fact I'm used to use the first one.
The second works for definition of function
func
but the compiler fails on defining the call operator ofstruct Adder
: "Adder has not been declared".