开发者

C++ functions problem

开发者 https://www.devze.com 2023-02-28 15:35 出处:网络
Is there a way for functions to call each other i.e. void menu() { some code here play(); ... } int play() { ...

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

精彩评论

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