我想做两个互相调用的函数,但是当我这样做时,一个函数因为未声明而出错

0 c++ forward-declaration

input()我调用的 中Table(),我收到一个错误,指出该函数未声明:

#include <iostream>

using namespace std;

void input(){
   Table();
}

void Table(){
   input();
}

int main(){
   input();
   Table();
}
Run Code Online (Sandbox Code Playgroud)

Mat*_*rün 5

在您尝试调用 Table() 时,该函数尚不清楚。添加前向声明以使其工作,如下所示:

using namespace std;

void Table();  // <-- forward declaration

void input(){ Table(); }
void Table(){ input(); }

int main(){ input(); Table(); }
Run Code Online (Sandbox Code Playgroud)