Where to extract functions for cleanup

I have a number of functions in my cpp file and I would like to do a bit of cleanup, move some functions to other files. My question is what would be the best approach to this?

Move the functions to a cpp file and create its own .h file to include in my main .h file?
Or move the functions to a cpp file and just declare them in my main header file?
I saw some open source projects, most functions like these were put into a .hpp file, though I haven't seen an option in my VS2010 to create one.
Move the functions to a cpp file and create its own .h file to include in my main .h file?

^ This.

I saw some open source projects, most functions like these were put into a .hpp file, though I haven't seen an option in my VS2010 to create one.

Not sure if you're implying the entire function was in the .hpp file. If so, that's not a good idea. Functions should be declared, but not defined in header files. If a function is defined in a header file and that header file is included in multiple source files, you will get linker errors.

It doesn't make any difference if header files have a .h or .hpp prefix. It's just a matter of style.

If you want to create a .hpp file in VS, just select the "Header file" icon for type of file. In the file name text area, change the .h extension to .hpp.


Last edited on
Those .hpp files had the whole function body in them. But they were defined as templates. Where should I put the templates?
Last edited on
Templates go in header files. Templates are a special case because templates are not expanded until the template is instantiated.
Topic archived. No new replies allowed.