Where to put non class member functions? you guys?

If you are doing some big program, usually, how do you organize the files? Put the class and its member in head file, but where to declare non member functions and where to define them? I don't want to put them all in one cpp file. If not, how to make them visible to the main cpp file? thanks.
closed account (o3hC5Di1)
Hi there,

Generally, each class gets its own .h and .cpp file. Free functions are put into files according to their purpose and / or according to the classes they operate on.

If you have free functions which operate on a certain class only, it is said those free functions are part of the interface of those classes and thus you should define those free functions in the same .h and .cpp files as the class itself.

Another handy tool for organizing code is the use of namespaces: http://www.cplusplus.com/doc/tutorial/namespaces/


As for making them visible in your main file, you only need to #include the .h files, the linker will do the rest for you.

Hope that helps.

All the best,
NwN
Thanks!
In a VERY LARGE class (like when I have to develop a complex Qt Widget with a lot of slots and functions) sometimes I split the .cpp context in more than one .cpp files (for example a .cpp file contains the class constructor, another file contains some functions, etc etc)

The header, instead, must be unique
Thanks!
Topic archived. No new replies allowed.