It is good style to sort methods in header files in the same order as in the .cpp file, but often this order gets crude during development.
以与.cpp文件相同的顺序对头文件中的方法进行排序是一种很好的方式,但通常这个顺序在开发过程中会变得粗糙。
How can I reorder the methods in the cpp file to the order given in the header file?
如何将cpp文件中的方法重新排序为头文件中给出的顺序?
3 个解决方案
#1
1
I've found it effective to use a graphical diff tool to show the header and source file side by side to keep the documentation in sync and make sure everything's in the same order. (My employer bought me Araxis Merge, so that's what I use, but there are a variety of free and commercial tools that accomplish the same thing on a variety of platforms.)
我发现使用图形差异工具并排显示标题和源文件以保持文档同步并确保所有内容都处于相同的顺序是有效的。 (我的雇主给我买了Araxis Merge,这就是我使用的,但是有各种各样的免费和商业工具可以在各种平台上完成同样的事情。)
This might be easier with a procedural C or C++ file, as opposed to an object-oriented C++ file where class member functions would have a different indentation level in the header than in the source file.
使用过程C或C ++文件可能会更容易,而不是面向对象的C ++文件,其中类成员函数在标头中的缩进级别与源文件中的缩进级别不同。
#2
0
The headline says: sort methods in cpp file by header
The body says: sort methods in header files in the same order as in the cpp file
Isn’t that contradictory? :-)
这不矛盾吗? :-)
While is possible to edit the header or source files either by some tool or by hand, in real life, it is very hard to enforce/maintain that order.
虽然可以通过某种工具或手工编辑标题或源文件,但在现实生活中,很难强制/维护该顺序。
My approach is to “view” the method names in alphabetical order. That is achievable by running doxygen on the files. In the doxygen config file, the following two options might be useful
我的方法是按字母顺序“查看”方法名称。这可以通过在文件上运行doxygen来实现。在doxygen配置文件中,以下两个选项可能很有用
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = YES
#3
0
You can use a modeller (such as Umbrello) to model your classes and generate the appropriate code.
您可以使用建模器(例如Umbrello)为类建模并生成适当的代码。
#1
1
I've found it effective to use a graphical diff tool to show the header and source file side by side to keep the documentation in sync and make sure everything's in the same order. (My employer bought me Araxis Merge, so that's what I use, but there are a variety of free and commercial tools that accomplish the same thing on a variety of platforms.)
我发现使用图形差异工具并排显示标题和源文件以保持文档同步并确保所有内容都处于相同的顺序是有效的。 (我的雇主给我买了Araxis Merge,这就是我使用的,但是有各种各样的免费和商业工具可以在各种平台上完成同样的事情。)
This might be easier with a procedural C or C++ file, as opposed to an object-oriented C++ file where class member functions would have a different indentation level in the header than in the source file.
使用过程C或C ++文件可能会更容易,而不是面向对象的C ++文件,其中类成员函数在标头中的缩进级别与源文件中的缩进级别不同。
#2
0
The headline says: sort methods in cpp file by header
The body says: sort methods in header files in the same order as in the cpp file
Isn’t that contradictory? :-)
这不矛盾吗? :-)
While is possible to edit the header or source files either by some tool or by hand, in real life, it is very hard to enforce/maintain that order.
虽然可以通过某种工具或手工编辑标题或源文件,但在现实生活中,很难强制/维护该顺序。
My approach is to “view” the method names in alphabetical order. That is achievable by running doxygen on the files. In the doxygen config file, the following two options might be useful
我的方法是按字母顺序“查看”方法名称。这可以通过在文件上运行doxygen来实现。在doxygen配置文件中,以下两个选项可能很有用
SORT_MEMBER_DOCS = YES
SORT_BRIEF_DOCS = YES
#3
0
You can use a modeller (such as Umbrello) to model your classes and generate the appropriate code.
您可以使用建模器(例如Umbrello)为类建模并生成适当的代码。