I can define the body of a class constructor in the class .h file or in the implementation file .cpp. These two styles are probably identical as far as the compiler is concerned within a specific project (project for me means DLL). Same applies to any member functions really: they can be defined in the header file or just declared there and then defined in the cpp file.
However, I found that if I need to include such class header file(s) in different projects (meaning that ultimately the code that uses the header file ends up in a different DLL) then having the actual implementation in the header file causes some headaches at compilation (not at linking... I don't even get to that point). Why? Well I won't go too much in detail but the compiler obviously tries to resolve all the functions which might be defined in other header files etc., forcing the poor developer to start pulling in various header files etc.
Isn't it always best to keep header files free of any implementation and just use them for 'declarations'? That would make it easier to include them in more than one projects w/o having to carry around a lot of extra junk.
What is your opinion about this?
See Question&Answers more detail:os