I tend to prototype C++ classes as a self-contained class, i.e. like:
class BlahBlahBlah
{
public:
void SomeMethod()
{
// some code here
}
};
and then later when I am happy with the design I will turn it into a .h/.cpp pair. This is mostly a mechanical task 开发者_如何学Cso is there any tool out there that can help with that?
Try Lzz.
Visual Assist has a refactor tool that does this. You can bind it to a keyboard shortcut so you can do it case-by-case, rather than robotically.
As an alternative to Lzz you might consider taking a look at Preprocess - A preprocessor for C and C++ modules. Unlike Lzz, it does preserve comments. However, it does have some limitations. It does not support namespaces or nested classes. But since it's written in PERL and I imagine it would not be too difficult to extend and customize.
There is also inlsplit: Inline C++ Source and Header splitter. It is a very simple awk script which parses a single .inl file and places all member functions with a @ folowing their prototype into the source file, keeping only the declaration in the header. There is also a @source tag for code to go straight into the implementation. Compared to lzz and preprocess, it is very lightweight. However it has been abandoned and there is no new development.
精彩评论