如何有两个相互调用C++的函数

con*_*ice 11 c++ mutual-recursion

我有2个这样的函数,它对if循环进行模糊处理:

void funcA(string str)
{
    size_t f = str.find("if");
    if(f!=string::npos)
    {
        funcB(str);        //obfuscate if-loop
    }
}

void funcB(string str)
{
     //obfuscate if loop
     funcA(body_of_if_loop);     //to check if there is a nested if-loop
}
Run Code Online (Sandbox Code Playgroud)

如果我放在前面,问题funcA就是无法看到funcB,反之亦然.funcBfuncA

非常感谢这里的任何帮助或建议.

she*_*heu 15

你想要的是前瞻性声明.在你的情况下:

void funcB(string str);

void funcA(string str)
{
    size_t f = str.find("if");
    if(f!=string::npos)
    {
        funcB(str);        //obfuscate if-loop
    }
}

void funcB(string str)
{
     //obfuscate if loop
     funcA(body_of_if_loop);     //to check if there is a nested if-loop
}
Run Code Online (Sandbox Code Playgroud)


bil*_*llz 10

一个向前声明将工作:

void funcB(string str); 

void funcA(string str)
{
    size_t f = str.find("if");
    if(f!=string::npos)
    {
        funcB(str);        //obfuscate if-loop
    }
}

void funcB(string str)
{
     //obfuscate if loop
     funcA(body_of_if_loop);     //to check if there is a nested if-loop
}
Run Code Online (Sandbox Code Playgroud)