Function body in header file?

Hey,

Very new to c++! One of those kids who did Java for years and left scratching his head over the extra complexities that c++ brings.

I'm getting the hang of it, but something confuses me..

My understanding of header files is that you define a method to be used in the .cpp file. Why am I coming across examples that (for example) actually fill out the method body?

1
2
3
4
  	PrimitiveType	GetType() 
	{ 
		return type;
	}


or

1
2
3
4
5
6
7
8
9
	inline void	ShadePixel(uint x, uint y, const Colour&c) 
	{
		if(y >= screenHeight) 
		{
			return;
		}
                ...

	}


Thanks in advance!

Smittey
Last edited on
Hiya, and welcome to hell. We have ginger snaps of unreal quality. :D

Sometimes it makes sense to have an inline function for performance reasons, especially if the functions are short. Compilation times will drop somewhat because of inline functions, and in cases of whole classes being defined inline, this can really bloat up files. It's generally a good practice not to do it.

-Albatross
Hah!

Ah ok, thanks! So this way of defining is almost exclusively for inline methods? If so, that first example I gave (which isn't inline), why does/can that still have a method body of 'return type;'?

- Smittey
Topic archived. No new replies allowed.