Question

Given a source file source.cpp how I can generate the appropriate headers source.hpp ?

I'm under linux 64 bit and I would like to avoid writing the headers by hand to reduce the amount of time that I spend on writing code and limit the possible errors.

Was it helpful?

Solution

You cannot generate appropriate headers from source files automatically, because there is no formal definition about what an appropriate header is. Especially, a tool that extracts declarations from a source file has no way of knowing whether a declaration should be private to a translation unit or shared among other translation units. In the first case, the declaration in the header would be IMHO inappropriate.

OTHER TIPS

You cannot really generate the code for your headers as there are things that are in the header that you cannot guess from the cpp file. The first things that come to my mind are the accessibility (public/protected/private) and inheritance.

What you can do however if you're trying to improve your workflow/productivity is using an IDE which has a lot a built in functionalities to help you edit the code. Creating a new class would for example create the header and cpp file, add an eventual inheritance, header guards, etc. It can help you renaming symbols to ease refactoring for example as well.

I personally use QtCreator which is free (as in free beer and free speech) but it's only a preference. I used Visual Studio as well with the Visual Assist X plugin (commercial), which provides some nice functionalities as well. I know that there are people that like Eclipse CDT, but I never really used it.

Choosing an IDE is only a matter of preference anyway ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top