Here is the question that arises again and again in the implementation of the C ++ class. I'm curious what people think here. Which code do you prefer and why?
class A { public: void publicCall(void); private: void f(void); CMyClass m_Member1; };
from
void A::publicCall(void) { f(); } void A::f(void) {
Or an alternative:
class A { public: void publicCall(void); private: void f(CMyClass &x); CMyClass m_Member1; };
from
void A::publicCall(void) { f(m_Member1); } void A::f(CMyClass &x) {
I think I always prefer the latter, because then f can work in any instance of CMyClass , but, nevertheless, I have a lot of code where the first is completely true, since f will only work on m_Member1 , and I really break up its two functions to make the code more readable.
Yes, this is more a moot point than a "answer" question, but I'm more interested in reasoning. I will mark as an answer an answer that gives good reasoning or a good criterion.
Also, keep in mind that this is just a toy example. The class will be larger than it really is, and therefore organization is important.
Chris A.
source share