好久沒做事情,也就沒什麼內容可更新的。這兩天開始做事情了,問題就不斷地出現了,就連使用標準的complex類都出問題。先說說問題吧。
xxxx.cpp: In member function ‘void xxxx::xxxxxxxx()’:
xxxx.cpp:100: error: ISO C++ forbids declaration of ‘type name’ with no type
xxxx.cpp:100: error: expected primary-expression before ‘double’
xxxx.cpp:100: error: expected ‘;’ before ‘double’
make: *** [mdqr.o] Error 1
編譯的時候報錯,其實那一行就是申請一塊double類型複數的數組記憶體,
// xxxx.cpp
#include <complex>
using std::complex;
...
// complex<double>* eig;
eig = new complex<double>[N]; // this is line 100
標頭檔和命名空間都使用了的阿,而且在標頭檔類中聲明
complex<double>* eig的時候還沒有報錯。寫一個最簡單的例子,測試complex的使用。如下,
#include <iostream>
#include <complex>
using std::complex;
using std::cout;
using std::endl;
int main(){
complex<double>* eig = new complex<double>[3];
eig[0] = complex<double>(1,2);
cout << eig[0] << endl;
return 0;
}
編譯通過,運行結果正確。到底是是為什麼xxxx.cpp裡面會出現問題呢?
後來同學建議使用typedef complex<double> dcmplx_t;改了之後的代碼如下,
// xxxx.cpp
#include <complex>
using std::complex;
typedef complex<double> dcmplx_t;
...
// dcmplx_t* eig;
eig = new dcmplx_t[N];
這樣就可以編譯了,結果也是正確的。但還是沒找到之前錯誤的原因。
在ubuntu10.04上編譯的,gcc-g++版本4.4.3, 程式中使用了LAPACKE庫。
那就先這樣了,希望知道原因的能幫忙解釋下。