If fn functions use state C1, use discontinuous encapsulation?
This using statement does not break encapsulation; it does not return any private state from C1 or does not prevent C1, preserving its invariants. This is just a convenient way to expose any other fn elements of C1 has - in this case int fn(int) - so they can be taken into account when resolving calls. Think of it as functionally equivalent ...
class C2 : public C1 { ... inline int fn(int j) { return C1::fn(j); } };
... but better, because you do not need to manually add and remove functions to synchronize with the C1 overload list.
If the fn () functions do not use state C1, should you declare that the helper class is the best way?
If they do not use state C1, they must be static or non-member. In my opinion, helper classes are an ugly idea. Namespaces are a common method of grouping functionality in C ++. I am fully aware of Professor Lakosβs recommendations for using classes and understanding all arguments and still disagree. I am happy to miss it if the mention of auxiliary classes was something more important for you.
source share