template method pattern and long parameter lists in c++

こ雲淡風輕ζ 提交于 2019-12-06 15:25:46

Yes, use enums (not defines) instead of true/false. That way, if you get the parameters out of order, then the compiler will complain. Also, it's much clearer to readers.

As for dealing with with long parameter lists in general --- hide them behind a typedef, or a generator that fixes some of the template parameters, and lets you vary the others.

I would rather reconsider my design if I had a template parameter list which is THAT long. Many parameters are often an indication of bad design.

I don't do c++, and this may not apply well to template, but what I would try to do with a normal method with a long parameter list is find related parameters and try to group them sensibly and introduce parameter objects reflecting the grouping, so that you have a shorter list of more complex parameters.

I would rater pass a single argument which is a collection of a variant type, for example a std::vector.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!