2012-11-14 31 views
1

我是新來的C++和SWIG錯誤C2062:鍵入int意外

我在Windows環境中使用SWIG創建一個python模塊。

創建包裝類(example_wrap.cxx)後。開始使用(python setup.py build_ext --inplace)創建python模塊。

但我得到* example_wrap.cxx(3090):錯誤C2062:類型 '詮釋' 意外*

GradedComplex.h:

class GradedComplex 
{ 
public: 
    typedef std::complex<double> dcomplex; 
    typedef Item<dcomplex> item_type; 
    typedef ItemComparator<dcomplex> comparator; 
    typedef std::set<item_type, comparator> grade_type; 

private: 
    int n_; 
    std::vector<grade_type *> grade_; 
    std::vector<double> thre_; 

public: 
    GradedComplex(int n, double *thre); 
    ~GradedComplex(); 

    void push(item_type item); 
    void avg(double *buf); 
}; 

#endif 

GradedComplex.cc

GradedComplex::GradedComplex(int n, double *thre) 
{ 
    n_ = n; 
    for (int i = 0; i < n_; ++i) 
    { 
    thre_.push_back(thre[i]); 
    grade_.push_back(new grade_type()); 
    } 
} 

然後我建立它使用SWIG生成python模塊。 Swing接口文件(example.i) GradedComplex(int n,double * thre);

我不是痛飲接口文件

產生的包裝類有大量的代碼更專業,所以我粘貼一些。

代碼:example_wrap.cxx

3083: #define SWIG_FILE_WITH_INIT 
3084: #include "Item.h" 
3085: #include "GradedComplex.h" 
3086: typedef std::complex<double> dcomplex; 
3087: typedef Item<dcomplex> item_type; 
3088: typedef ItemComparator<dcomplex> comparator; 
3089: typedef std::set<item_type, comparator> grade_type; 
3090: GradedComplex(int n, double *thre); 
3091: void push(item_type item); 
3092: void avg(double *buf); 
3093: #include <string> 
3094: #include <complex> 
3095: #include <iostream> 
3096: #if PY_VERSION_HEX >= 0x03020000 
3097: # define SWIGPY_SLICE_ARG(obj) ((PyObject*) (obj)) 
3098: #else 
3099: # define SWIGPY_SLICE_ARG(obj) ((PySliceObject*) (obj)) 
3100: #endif 

的GradedComplex構造:

GradedComplex::GradedComplex(int n, double *thre) 
{ 
    n_ = n; 
    for (int i = 0; i < n_; ++i) 
    { 
    thre_.push_back(thre[i]); 
    grade_.push_back(new grade_type()); 
    } 
} 

請提出一個糾正這個錯誤

+0

3102行仍然丟失。 –

+0

@KirillKobelev這是一個錯誤。抱歉給你帶來不便 。我已糾正它。 –

+4

GradedComplex(int n,double * thre);沒有返回類型。 – imreal

回答

1

你顯然聲明GradedComplex類的地方在一些頭文件(GradedComplex.h?)

後來你試圖在這一行

GradedComplex(int n, double *thre); 

使用這個名稱來人類讀者這條線可能會看起來像一個試圖宣佈獨立功能GradedComplex。從技術上講,具有與現有類相同名稱的函數是合法的。但是,由於您沒有爲此函數指定返回類型,因此編譯器不會將其視爲函數聲明。編譯器會認爲你只是試圖宣佈與周圍的聲明符冗餘括號型GradedComplex的對象,如

GradedComplex (a); 

出於這個原因,int的出現混淆,並導致錯誤報告有關意外int在行3090.

你想做什麼?如果您試圖爲GradedComplex定義構造函數,那麼您已經知道如何去做(您自己發佈了一個正確的定義)。 3090行的目的是什麼?你爲什麼寫這行?

+0

我會把更多的示例代碼 –

+1

@svs_swig:不需要更多的代碼。會發生什麼是我在上面我的回答中所描述的。 – AnT

+0

感謝您的信息 –

1

你不能有一個函數在C沒有返回類型++ 。您應該爲函數GradedComplex設置返回類型。構造函數不能這樣聲明。

+0

感謝您的寶貴時間 –