Sign in to follow this  
bulletthebluesky

A question about functions

Recommended Posts

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.

Share this post


Link to post
Share on other sites
jyk    2094
Quote:
Original post by Promethium
Or even better, since your writing C++, use classes [smile]
Well, 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.

Also, note that the issue in question applies to classes as well; the problem of declaration order is not specific to functions.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this