function/class definitions and implementations in header files

Hi,
I was wondering if there was any reason to split up function or class definitions
and implementations between a header file and a cpp file.
(ie definitions going to .h file & implementations going to .cpp file)

In most cases I've been putting all of it into a header file like this:


// header file doing something
#ifndef __HEADER__
#define __HEADER__

void newFunc();

void newFunc()
{
    cout << "this is a function that does something\n";
}

#endif


So far all of the code I've written by this method works fine. However I've not written anything too extensive yet. I just want to make sure I'm not painting myself into a corner down the line.

Thanks!
-- Mark
It can help cut down on compilation times when you redo certain functions.

In your current system, if you change the function definition, even without changing the signature (i.e. the arguments/name), you will still have to recompile all files that use it.

If you split them up, as long as the function signature remains the same, you won't have to recompile your old files.
Topic archived. No new replies allowed.