The barebones version of a .cpp file is often not much more than a copy of the related header file with some braces instead of semicolons, ClassName::
inserted in a few places, and removing the virtual
keyword. Much of it could be generated with a one-line sed
command, but it wouldn't be very robust for all the language features (templates come to mind).
Before I go write my own, are there any simple command-line utilities that will take a header file I provide and give me a skeletal .cpp file where I can fill in the blanks?
Cpp files don't always have to have a header file associated with it but it usually does as the header file acts like a bridge between cpp files so each cpp file can use code from another cpp file. One thing that should be strongly enforced is the no use of code within a header file!
A header file is a file with extension . h which contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer writes and the files that comes with your compiler.
The short answer is that a . h file contains shared declarations, a . cpp file contains definitions and local declarations. It's important that you understand the difference between declarations and definitions.
Most graphical editors have some plugins available to do that like vim, gedit or Eclipse. But I am not aware of a shell or perl script to do that.
Eclipse CDT has a feature of creating setters/getters provided you have defined variables in your .h. Also it provides "Implement method" - again it looks through your definitions in .h and implements methods giving them empty body. Maybe someone find this usefull.
And don't forget to read question, pointed by larsmans.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With