2015-03-19 74 views
0

我把'(RE)'放在void F(),但我接近了一個有趣的問題與我的程序。當我將(RE)置於我的空白F()時,我的void RE()被編碼在void F()以上,那麼void RE()將如何能夠知道void F()? Visual Studio不會讓我用這種方式運行我的程序。我認爲他們被宣佈爲main()之外的無效函數,所以我認爲那些工作在任何地方。如何獲得一個void函數在C++中使用另一個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() 

回答

3

函數可以有declarationsdefinitions。爲了能夠調用一個函數,你所需要的代碼就是能夠看到一個聲明。

因此,提供REF的聲明,然後定義它們。

void RE(); 
void F(); 

//RE and F definitions here. 
+0

哦,上帝......爲什麼我打擾問這個......我的大腦最近一直在失敗。非常感謝你。 – CR9191 2015-03-19 03:57:38

1

RE()一個聲明F()前:

void RE(); 

void F() 
{ 
    ... 
} 

void RE() 
{ 
    ... 
} 
相關問題