简体   繁体   中英

How to get a void function to work with another void function in C++?

I put '(RE)' in void F() , but I approached one funny problem with my program. When I put (RE) in my void F() , my void RE() is coded above the void F() , how would the void RE() be able to know the void F() ? Visual Studio wont let me run my program this way. I thought they were declared as void functions outside main() so I assumed those would work anywhere.

.
.
.
.
.
void F()
{
    if (nextChar() == 'a')
        match('a');
    else if (nextChar() == 'b')
        match('b');
    else if (nextChar() == 'c')
        match('c');
    else if (nextChar() == 'd')
        match('d');
    else if (nextChar() == 'a')
    {
        match('(');
        RE();      //HOW????
        match(')');
    }
}

void RE()
{
    if (nextChar() == 'a')
    {
        RE();
        RE();
    }
    else if (nextChar() == 'a')
    {
        RE();
        match('|');
        RE();
    }
    else if (nextChar() == 'a')
    {
        RE();
        match('*');
    }
    else if (nextChar() == 'a')
        F();                   //How????
}


int main()

Functions can have declarations and definitions . To be able to call a function, all you code needs is to be able to see a declaration.

So, provide declarations for both RE and F and then define them.

void RE();
void F();

//RE and F definitions here.

Put a declaration of RE() before F() :

void RE();

void F()
{
    ...
}

void RE() 
{
    ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM