I keep hearing it's wrong, but I do it anyway. Between me and myself, I'm used to placing functions/classes in header files and "executable" code (eg. globals, main()) in source files.
Yes, I keep hearing it's wrong... :rolleyes:
Printable View
I keep hearing it's wrong, but I do it anyway. Between me and myself, I'm used to placing functions/classes in header files and "executable" code (eg. globals, main()) in source files.
Yes, I keep hearing it's wrong... :rolleyes:
I think you mean you put function prototypes in header files. If you put the whole function in the headers the linker would complain about duplicate symbol declarations if you include that header in two or more *.c or *.cpp files.Quote:
Originally Posted by jafet
And I don't think anyone has said that is wrong. That's the way it is supposed to be done. That's what God created header files for ;)
Nope, I meant what I meant. I put entire CLASSES, function DEFINITIONS and the like into .h files. .cpp files houses main(), globals, code, small specialized functions etc. I do preprocessor checking on the header files so nothing goes wrong. AND I rarely go to the trouble to write function declarations; to me they're a waste of space. Call it habit :rolleyes:
So you are inventing your own way of using headers and source files eh.
Good luck with that. :rolleyes:
how does it require more typing?Quote:
Originally Posted by swgh
versusCode:// x.h
class X
{
public:
// note that the "inline" here is not really necessary
inline int someFunc() { return 5; }
};
seems about the same to me. if anything, the inline is shorter.Code:// x.h
class X
{
public:
int someFunc();
};
// x.cpp
int X::someFunc()
{
return 5;
}
BTW inlining can also slow your code down too! it can result in a bigger executable, which can cause page misses, etc.
have a read of this FAQ