2012-04-27 59 views
-6

可能重複:
Calling functions from main() in c++指南改變INT主()

有一些什麼guidlines改變INT主調用等功能於你的代碼,我被告知不要使用int main2(),int main3()等我也該如何聲明它們,以便編譯器調用它們並識別它們是否是

#include <iostream> 
int main() 
int main 2() 
using namespace std; 

int main() 
    code here ..... 1st function 
int main2() 
    code here .... 2nd function 

還是會

#include <iostream> 
int anothername() 
int seconddifferentname() 
using namespace std; 

int anothername() 
    code here ..... 1st function 
int seconddifferentname() 
    code here .... 2nd function 
+2

你想知道如何命名除「主」本身之外的其他功能嗎? – 2012-04-27 06:20:50

+0

是的cristian K我這樣做會很有幫助 – HK3008 2012-04-27 23:26:42

回答

1

創建新的功能,並從主稱他們爲:

void foo() {} 
void goo() {} 

int main() 
{ 
    foo(); 
    goo(); 
} 

沒有什麼技術上的錯誤具有main1main2方法的,但有一個有效的只有一個入口點C++程序,那就是main