And it runs well if i call timed_text(string,double) until the last character. At which point it give me the error in the file xstring: string subscript out of range.
However when i define it as a function in a cpp file, it works just fine. any ideas why this is happening?
oh trust me i have, i actually did figure out the problem, and it actually wasn't that. It's that my header was saving to one place, when the header i was including was elsewhere. Sorry for the stupid problem :P
to be able to easily re-use them mostly. Is it a bad thing to do? If so (which by your question i have a feeling it is), please explain why, I'd be happy to learn :)
You see, header files are copy-and-pasted into the place where they are #include d (that's what the directive does!). If you post implementations that translate into compiled code, then when your compiler tries to combine your two files via linking, you'll get redefinition errors.
@Albatross, oooooohhhhhhhhhh :P Alright I understand, but does that truly mean it's a bad thing as long as you don't redefine the header implementation? What I mean is, if you just call the function, and never redefine the function, is there any harm done? Why is it that we often post the function definition after it's declaration?
In another threat (that now I can't find): Alice: Why I should not include .cpp ? Bob: Because it kills the purpose of having a linker. If you modify the main.cpp, you will need to recompile the included cpp files (that did not change), ending with higher compilation time.
... but i'm not including a cpp? Every cpp in a project is compiled unless not changed, by including it in another cpp, and if that second cpp changes, the compiler would recompile the first cpp because (i'm now presuming) of the copy paste effect albatross mentioned.
but this is a constant header file with a constant definition of a function. the function is called in the cpp as if defined in the cpp itself, but it's not, it's defined in the header as some function like cout or cin would be. Increasing the overall organization of the code (if you comment about where this strange header came from and why it's there at least).... at least in theory.
Am i wrong? again, if so, please explain. I'm liking this thread for how much it's teaching me.
Why is it that we often post the function definition after it's declaration?
i know that often times when i post code i put the classes and the definitions in main cpp file to make things easier to read rather then break up the code for every file. that way someone can just copy and paste to run it without hassle. i know im not the only one.
In int main(){ is all the logic of the program. I just expect to be the "first" thing I see.
Besides if you put only the prototypes you will immediately know what functions you have, how you must call them, and you get an idea of what they do.
The other method will work, just adopt a convention.
headlessgargoyle: ... but i'm not including a cpp? Bob: irrelevant. You are including the definitions of your functions. headlessgargoyle: but this is a constant header file with a constant definition of a function. Bob: Yeah, and you are compiling it over and over again when you could just generate a object code that will be latter linked.
If you are interested read something about makefiles.
btw: rocketboy9000 was right. Arrays go from 0 to size-1, but you are trying to access content[length] that is out of bounds. Your program didn't crashed because you were unlucky.
@spinelessbasilisk (whoops)
Having the header define the implementations kills any possibility of #including the header in two or more C++ files in your project. Remember: all #include does is copy-and-pastes. If you have the same definition in two different files, that causes a redefinition error. Sorry. :P
And posting the definition after the declaration at least in the main C++ file is just so that you don't have to scroll down through tons of code to get to main(). Generally, functions are either long sections of code, or shorter pieces of code that get used a lot. :)
@albatross, though i don't understand the reference to spinelessbasilisk, that answers my question perfectly (or at least i understood your answer better than the others). thank you. and you answered the question about why we put declarations after main () in a matter that i understood too.
@ne555, i'm not 100% on what you're saying, but i don't quite understand linkage yet. And i shall look into makefiles as well.
@rocketboy9000/ne555, i'm unsure why it's working on my computer.... but it is, so i dunno :P I use MSVS 2010, if that makes a difference. EDIT: but i changed it to what you said to be safe.
@cranium :P
@ all, thanks for all your help, and thanks for getting me to over 100 posts :P
yes, but clock() measures only the time used by your app, so, if you're running crysis in the background, the wait time will be different. Usually it's best to stop your process and get the OS to resume it after a pause.