如何在C++中使一个void函数与另一个void功能协同工作



我把'(RE)'放在void F()中,但我的程序遇到了一个有趣的问题。当我把(RE)放在我的空F()中时,我的void RE()被编码在void F()之上,void RE()怎么能知道void F()?Visual Studio不允许我以这种方式运行程序。我认为它们在main()之外被声明为void函数,所以我认为它们可以在任何地方工作。

.
.
.
.
.
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()

函数可以有声明和定义。为了能够调用一个函数,代码所需要的就是能够看到一个声明。

因此,为REF提供声明,然后定义它们。

void RE();
void F();
//RE and F definitions here.

F():之前放入RE()声明

void RE();
void F()
{
    ...
}
void RE() 
{
    ...
}

最新更新