2012-03-19 66 views
-2

什麼是錯的,我得到錯誤的下面的代碼的程序

#include "parent_child.h" 
#include "child_proces.h" 

int main() { 

    childprocess::childprocess(){} 
    childprocess::~childprocess(){} 
    /* parentchild *cp = NULL; 
     act.sa_sigaction = cp->SignalHandlerCallback; 
     act.sa_flags = SA_SIGINFO; 
     sigaction(SIGKILL, &act, NULL); 
    }*/ 
    printf("Child process\n"); 

    return 0; 
} 

ERROR: child_proces.cpp: In function âint main()â: child_proces.cpp:11: error: expected ;' before â{â token child_proces.cpp:12: error: no matching function for call to âchildprocess::~childprocess()â child_proces.h:9: note: candidates are: childprocess::~childprocess() child_proces.cpp:12: error: expected ;' before â{â token

回答

4

不能定義構造函數和析構函數或任何其他方法的另一個函數內此事(包括main)。

將定義移到main之外,最好在對應於"child_proces.h"的實現文件中 - 如"child_proces.cpp"

爲了得到它來編譯,你可以嘗試:

childprocess::childprocess(){} 
childprocess::~childprocess(){} 

int main() 
{ 
//... 
} 
0

您需要定義main功能之外的方法。

childprocess::childprocess(){} 
childprocess::~childprocess(){} 

int main() {} 

而且,你爲什麼聲明在首位的構造函數和析構函數,如果你不打算在他們做什麼?

0
#include "parent_child.h" 
#include "child_proces.h" 
childprocess::childprocess(){} 
    childprocess::~childprocess(){} 
int main() { 


    /* parentchild *cp = NULL; 
     act.sa_sigaction = cp->SignalHandlerCallback; 
     act.sa_flags = SA_SIGINFO; 
     sigaction(SIGKILL, &act, NULL); 
    }*/ 
    printf("Child process\n"); 

    return 0; 
} 
相關問題