2012-07-10 67 views
0

somefile.h返回類型默認爲 'INT' 在C代碼

內容
#ifndef __SOMEFILE_H 
#define __SOMEFILE_H 

#ifdef __cplusplus 
extern "C" { 
#endif 

typedef struct _table_t table_t; 

struct _table_t 
{ 
    void (*somefunction1)(); 
    void (*somefunction2)(int a); 
    void (*somefunction3)(int a, int *b); 
}; 

#ifdef __cplusplus 
} 
#endif 
#endif <-- I am getting the error here 

somefile.h被包括在兩者的.cpp和.c文件。當這個項目是建立在Linux上,我得到以下錯誤:

error: return type defaults to 'int'

我該如何解決這個問題?

+0

不要使用'__SOMEFILE_H',這些名字被保留用於執行。 – 2012-07-10 15:52:40

+0

@丹尼爾,它實際上是一個不同的名字,我只是爲了簡單而在這裏發佈。 – RRR 2012-07-10 15:54:58

+2

請發佈您的實際頭文件,但這並不反映您的問題 – ouah 2012-07-10 15:58:02

回答

3

您有一個沒有定義返回類型的函數。尋找類似

Foo(void); 

Foo(void) { 
    printf("foo you too"); 
} 
+3

+1爲「你也是」。 – Peres 2012-07-10 16:08:51

+0

謝謝。但爲什麼我在.h文件中得到這個錯誤? – RRR 2012-07-10 16:17:53

+0

@RRR如果這個聲明是'#include'之後的第一個東西,那麼你的編譯器可能會感到困惑。你使用什麼編譯器?你能同時提供'.c'和'.h'文件,所以我們可以嘗試重現錯誤? – 2012-07-10 16:31:07