Switching from main function to other function issue.

For some reason i cannot transfer control from the main function to a new function, any reason why it's not working would be great. :)

I am doing this:
1
2
3
4
5
6
7
8
9
10
11
12
13
using namespace std;

int main()
{
	newgame();

	return 0;
}

void newgame()
{
	return;
}




It claims the "newgame" identifier is not found.

How could i solve this problem?
It's because that during compiling at line 5 the compiler doesn't know about the newgame() function.
You need to declare the function as follows: (that way the compiler will know that a function called newgame exists and wouldn't be surprised);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
using namespace std;
void newgame(); //function declaration

int main()
{
	newgame();

	return 0;
}

void newgame()
{
	return;
}
Okay, thank you VERY much for the help! :)

very brief and informative! :D
You could also move newgame to be above main in the source ile. That would remove the need to declare the function. guestgulkan's way is more 'correct' allowing the order of functions in the file to not matter. The way I suggest is good for a quick 'hack'. Explaining this will hopefully also improve your understanding of what is going on.
Hmm... another duplicate thread...
http://www.cplusplus.com/forum/beginner/3108/
Topic archived. No new replies allowed.