complex編譯報錯

來源:互聯網
上載者:User

好久沒做事情,也就沒什麼內容可更新的。這兩天開始做事情了,問題就不斷地出現了,就連使用標準的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庫。

那就先這樣了,希望知道原因的能幫忙解釋下。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.