View Single Post
Old 03-03-2003, 08:14 PM   #3 (permalink)
alpha
Regular Contributor
 
Join Date: Feb 2003
Posts: 120
alpha is on a distinguished road
Send a message via AIM to alpha
functions must either be prototyped or defined above main. main is a function, the first function called, and returned to once a function that is called is complete. once main is done, the program is done.

functions can only see what is above them.

for example, for the code you posted. if you want function three to call function two, it can. but function two cannot call function three. if you prototype the funtions, i believe you could call function three from function two. (not sure though)

however, functions cannot call main.

hope this helps some.

edit:
Code:
#include <iostream>

void test_one();
void test_two();

int main()
{
	test_one();
	
	std::cin.get();
	return 0;
}

void test_one()
{
	std::cout << "Test One";
	std::cout << std::endl;
	test_two();
}

void test_two()
{
	std::cout << "Test Two";
	std::cout << std::endl;
}
this will output:

Test One
Test Two

you can call function two from one if it is prototyped and declared before main.
alpha is offline   Reply With Quote