好久没做事情,也就没什么内容可更新的。这两天开始做事情了,问题就不断地出现了,就连使用标准的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
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
#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 ;
}
#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];
#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库。
那就先这样了,希望知道原因的能帮忙解释下。