My class definition is spread across headers and source files:
// T.hpp
class T {
public:
void foo();
};
// T.cpp
void T::foo() {
}
If T::foo
needs to make use of some helper function that need be visible only to T
, which of the below solutions is best?
1. Private member
// T.hpp
class T {
public:
void foo();
private:
void helper();
};
// T.cpp
void T::foo() {
helper();
}
void T::helper() {
}
2. Free function accessible only in class definition's TU
// T.hpp
class T {
public:
void foo();
};
// T.cpp
namespace {
void helper() {}
}
void T::foo() {
helper();
}
Is there any difference except that with the former I will end up with more functions in the header file?