开发者

C++ functions problem

Is there a way for functions to call each other i.e.

void menu()
{
some code here
play();
...
}

int play()
{
...
menu();
...
retur开发者_JAVA百科n 0;
}


Add the declaration of the second function at the top of your code file:

int play();

void menu()
{
   // some code here
   play();
   // ...
}

int play()
{
   // ...
   menu();
   // ...
   return 0;
}

This is called a forward declaration, and it informs the compiler that an identifier will be declared later.
It is a way of denoting a function so that you can call it before you provide the complete definition.


Yes, but this is almost never what you want to do since careless use will break the stack.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜