Pregunta

Sorry for the noop question, but is it possible (In Visual C++ 2010 or some other IDE) to generate the header file automatically based on the variables and code in the actual source code (.cpp) files?

Thanks!

¿Fue útil?

Solución

Most IDE's support some command like 'Create class' which creates a skeleton .h/.cpp file pair for you.
Additionally the Eclipse CDT IDE supports a command 'Implement methods' that will create member function bodies from the declarations in the header file.

Another option is to use a separate or builtin CASE or UML tool that is able to generate code from your model (I think there's a free UML modelling plugin available for Eclipse, never used this myself though).

Otros consejos

*.h or *.hpp files are a part of the actual source code. So, in common case it is impossible.

No you cant generate the header file automatically. The build tools will do this for you.

Also check out Advanced Auto-Dependency Generation.

You could, in theory, write a compiler that is smart enough to do this for functions.

Of course, it would be really stupid about it. You may not want all the functions and variables you define to be in the header file.

And it would completely fail for classes, because those can't just sit in the .cpp file in the first place; copying them to the header would result in a duplicate definition.

The other way round is far easier (creating a skeleton .cpp from a header).

And then there's the Modules effort to bring a proper module system to C++. But that's quite some years in the future, so don't hold your breath.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top