I've got a class that consists of a few functions and a lot of operators. Almost all functions and operators use templates which is why I've implemented them in the header file. This made it pretty hard to find something in the code so I decided to move all operators into a seperate headerfile.
now I have something like:
fstring.h
class fstring{
...
#include "fstring_operators.h"
}
and fstring_operators.h
...
template<int RSIZE>
bool operator==(const fstring<RSIZE>& rhs) const {
return equals(rhs._chars, RSIZE);
}
...
Is it ok to do something like this? I've also omitted header guards for fstring_operators.h because it must not be included anywhere except in fstring.h
Although I've seen this in production code before, I don't really agree with this style for 2 reasons:
1) You expect a class
to be fully defined in the header. You shouldn't need to look inside other headers to find what you're looking for.
2) You can include the other header elsewhere. Even without include guards, it's not a guarantee it won't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With