Organization of Functions...header files?

Hi I am a long time matlab user but just getting into C/C++.

My question is concerning organization of code.

In matlab i organize my useful functions in a work folder with sub folders. When ever I am working on a new script I add my "work" folder to the path so that I can access all of my useful functions.

From what I have read, I think I want to basically use header files to organize my C++ functions in a similar manner. So lets same I have many functions for working with strings. I would:

1) create a StringFunctions.cpp file where I write many functions dealing with parsing and trimming strings etc.

2) then write a header file "stringfunctions.h" where I declare these functions.

3) then when I want to access these functions in a new project, I would do #include "stringfunctions.h"

Does this seem like a logical approach to building up my library?


If anyone could suggest a more logical approach or has any suggestions/articles that they think is useful I would be very interested.

Thanks,

L
You would also need to copy and paste the StringFunctions.cpp file into your new project or it will not be able to find the definitions of the functions; the header only has the declarations. What you can do instead is make the StringFunctions.cpp a .hpp file (.h is the same s .hpp, but you can have two files stringfuncs.h and stringfuncs.hpp (same name, different extension)) and include the .h file with the declarations in all your CPP files, and the .hpp file with the definitions in just one CPP file so the linker is happy.
Last edited on
Thanks. The renaming of cpp to h (etc) is a little confusing to me but I will experiment to see what works for me.

Is that approach standard practice?
Last edited on
Topic archived. No new replies allowed.