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...
Yeah
No
No but I do it anyway
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...
Code:#include <stdio.h> void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){ puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9 /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i] ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][ t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}
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.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
Code:#include <stdio.h> void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){ puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9 /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i] ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][ t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}
So you are inventing your own way of using headers and source files eh.
Good luck with that.
how does it require more typing?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
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?