繁体   English   中英

如何使void函数与C ++中的另一个void函数一起工作?

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

我将'(RE)'放入void F() ,但是我的程序遇到了一个有趣的问题。 当我将(RE)放入我的void 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.

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

void RE();

void F()
{
    ...
}

void RE() 
{
    ...
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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