Okay, I'm trying to re-compile the engine with an extra function that I've written, and in one place, I'm using malloc. The function malloc, being a std C function, is not included in C++. So, in the engine source file, should i just go ahead and include the <stdlib.h> header file, or should I use the 'new' operator? I probably should use the 'new' operator.....
Endar wrote:The function malloc, being a std C function, is not included in C++.
That is an incorrect statements in its entirety. You are able to use mallac as well as any ASCII C code in C++. That being said new is the usually recommended choice for C++ as if will call an objects constructor. mallac is just interested in the size of the object.
Rather than give you the answer I am going to send you on a learning lesson. Here is an website with an explanation of the differences of mallac and new how to use them correctly: :http://www.codeproject.com/tips/newandmalloc.asp
EDIT:
@thesmileman: I just now really looked at what I wrote about malloc not being included in C++ and I had a damn good laugh. I really have to pay more attention to what I write!
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
The array looks like its being declared alright, and I call it almost straight after it's been created and everything is fine, but then I call it later in the function and the compiler gives me an "undeclared identifier" error. I am thinking that it could be because it isn't actually declared at the start of the function, its declared inside the body of an 'else' condition.
Here's the layout (psuedocode):
Endar wrote:The array looks like its being declared alright, and I call it almost straight after it's been created and everything is fine, but then I call it later in the function and the compiler gives me an "undeclared identifier" error. I am thinking that it could be because it isn't actually declared at the start of the function, its declared inside the body of an 'else' condition.
I'd say you hit the nail on the head there... think it through, what if the if was true? Then the array has not been declared... so you can't call it.
It works fine with the while because that is still inside the else that declared the array.
Yeah, I see your point, but wouldn't that just be a runtime error instead of a compiler error?? It really doens't matter because if the 'if' is true, then it 'return's out of the function.
But I do think that I would just get a memory error at runtime instead of a compiler error.
"The reputation of a thousand years may be determined by the conduct of one hour."
-Japanese Proverb
By the way Endar, how old are you. I really have no idea but everytime I see cookie monster I think you are like 5 years old. Well I think of that and cookies and milk.