I have something like the following:
Then:
// foo.cpp: class foo::impl { public: void bar(ab, cd); void baz(ab, cd, ef, gh, ij); void quux(ab, cd, ef, gh, ij); private: // lots of private state, helper functions, etc. }; void foo::impl::bar(ab, cd) { ... } void foo::impl::baz(ab, cd, ef, gh, ij) { ... } void foo::impl::quux(ab, cd, ef, gh, ij) { ... } foo::foo() : m_pimpl(new impl()) { } foo::~foo() { delete m_pimpl; m_pimpl = NULL; } void foo::bar(ab, cd) { return m_pimpl->bar(b, d); } void foo::baz(ab, cd, ef, gh, ij) { return m_pimpl->baz(b, d, f, h, j) } void foo::quux(ab, cd, ef, gh, ij) { return m_pimpl->quux(b, d, f, h, j); }
There are many repetitions of bar , baz and quux here:
- Once the ad
foo - As soon as the declaration
foo::impl - Once in
foo::impl definitions - Twice in
foo definitions: once for foo list of function parameters and again to call the corresponding functions foo::impl .
For each of them, except the last, I have to write down the entire list of parameters, the types of which may be more involved.
What is the best way, if any, to reduce repetition here? One simple way is to embed the definition of public functions foo::impl , but is there anything beyond the fact that apart from designing classes, it is different to have fewer public functions?