How to have two functions that call each other C++
Asked Answered
W

2

12

I have 2 functions like this that does obfuscation on if loop:

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
}

The problem with this would be that funcA would not be able to see funcB and vice versa if I put funcB before funcA.

Would appreciate any help or advice here.

Worthen answered 30/1, 2013 at 7:34 Comment(2)
Why does everybody call it an if loop? There's absolutely no looping involved.Konyn
@Konyn well, it replaces for-loop construct, does it not?Dandify
H
21

What you want is forward declaration. In your case:

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
}
Hashimoto answered 30/1, 2013 at 7:38 Comment(0)
D
12

A forward declaration would work:

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
}
Dotson answered 30/1, 2013 at 7:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.