OK coming from a vb background ( a long time ago ) -- if I had a set of functions that were useful to a certain program i was making, I could create a file and add that to my projects. I can't remember what the name was, but anyway, it would include stuff like a quick way to convert to lowercases and remove spaces and things that dealt with the win api, etc.
Can I create the same type of file (or even download one for c++ that someone may have pre-made)?
I'm assuming this is a .h file?
Say for example I wanted to make a function that would do something silly like multiply an int by 4. I put this function in something.h
Then in any project I want to call that function, I just use:
#include <something.h>
correct?
And let's say that this:
1 2 3 4 5
int timesFour (int x) {
int temp;
temp = x * 4;
return temp;
}
Then as long as I included <something.h>, I could type anywhere in my current .cpp file:
a = timesFour(b);
and it will call that function right from something.h???
No I don't even know what an implementation file is.
I'm working mainly on math stuff now through the thinkcscpp.pdf and it's helping a lot to get familiar with the language...I just have these questions looming over my head that I don't feel that particular book is ever going to get to. Just trying to plan everything out.
Oh yeah I know the difference. I just wasn't sure if a .h file that I made myself could be re-used by my other applications...or if a function in a header file could be called directly from the source file (or implementation file).
If you want to reuse code, the purpose of a library pops up. Thelibrary has an interfaced declared in a header and you find the definition of the library via the header (and on Windows, via macros). You might also want to look up how the symbol system works and how to dynamically load a shared library.