A question about functions
I have a small question about c++ functions. When I recently started a large project, I noticed that whenever I wrote a function that referenced a function below it(physically in the code) it would throw an error. I think this is due to the compiler reading the code top to bottom. What can I do to work around this? See below for an example: (BTW my compiler is Visual C++ 2008 Express)
Code:
void Function1()
{
...
Function2();
}
void Function2()
{
...
}
End Code
Thanks.
Use a function declaration:
void Function2();void Function1() { Function2();}void Function2() {}
Quote:Original post by PromethiumWell, using classes wouldn't necessarily be 'better'; free functions have their place in C++, as does procedural programming in general. In any case, since we don't know what the OP is actually doing, we can't really say for certain that using classes would be a better choice.
Or even better, since your writing C++, use classes [smile]
Also, note that the issue in question applies to classes as well; the problem of declaration order is not specific to functions.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement