#include<iostream.h>
#include<math.h>
class array
{
public:
double *A[58];
array *ptr;
void initialize(void);
void output(array *ptr);
};
array EOSAI;
main()
{
EOSAI.initialize();
EOSAI.output(EOSAI.ptr);
}
void array::initialize(void)
{
int a,b;
double B[59]={0,0.153832600e0,1.341953000e0,-2.998583000e0,-0.048312280e0,0.375796500e0,-1.589575000e0,-0.053588470e0
,0.886594630e0,-0.710237040e0,-1.471722000e0,1.321850350e0,-0.786659250e0
//13
,0.229129e-08
//14-34
, 0.157672400e0,-0.436386400e0,-0.044081590e0,-0.003433888e0
, 0.032059050e0, 0.024873550e0, 0.073322790e0,-0.001600573e0
, 0.642470600e0,-0.416260100e0,-0.066899570e0, 0.279179500e0
,-0.696605100e0,-0.002860589e0,-0.008098836e0, 3.150547000e0
, 0.007224479e0,-0.705752900e0, 0.534979200e0,-0.079314910e0
,-1.418465000e0
//35
,-0.599905e-16
//36-58
, 0.105840200e0, 0.034317290e0,-0.007022847e0, 0.024955870e0
, 0.042968180e0, 0.746545300e0,-0.291961300e0, 7.294616000e0
,-9.936757000e0,-0.005399808e0,-0.243256700e0, 0.049870160e0
, 0.003733797e0, 1.874951000e0, 0.002168144e0,-0.658716400e0
, 0.000205518e0, 0.009776195e0,-0.020487080e0, 0.015573220e0
, 0.006862415e0,-0.001226752e0, 0.002850908e0};
b=58;
EOSAI.ptr=&EOSAI;
for(a=0;a<=b;a++)
{
EOSAI.ptr->A[a]=B[a]; //此行错误!!!!!!!!!!!!!!
}
}
void array::output(array *ptr)
{
int a,b;
b=58;
for(a=0;a<=b;a++)
{
cout<<A[a]<<"\n";
}
}
错误出在此行: EOSAI.ptr->A[a]=B[a]; 显示是illegal use of floating point
我还写过小程序试过,整数数组就没问题,一旦改成float或者double即使编译时不出错,运行时也会出错:General Protection Fault in module
PS:类成员数组赋值问题好烦啊,有没有大虾给个较好的方法可以批量给类成员double数组赋值,我正把一个fortran程序改写成C++,超多的全局变量需要赋值。大家有没有什么好办法对付Fortran中大量的common变量呀。。。。。
#include<math.h>
class array
{
public:
double *A[58];
array *ptr;
void initialize(void);
void output(array *ptr);
};
array EOSAI;
main()
{
EOSAI.initialize();
EOSAI.output(EOSAI.ptr);
}
void array::initialize(void)
{
int a,b;
double B[59]={0,0.153832600e0,1.341953000e0,-2.998583000e0,-0.048312280e0,0.375796500e0,-1.589575000e0,-0.053588470e0
,0.886594630e0,-0.710237040e0,-1.471722000e0,1.321850350e0,-0.786659250e0
//13
,0.229129e-08
//14-34
, 0.157672400e0,-0.436386400e0,-0.044081590e0,-0.003433888e0
, 0.032059050e0, 0.024873550e0, 0.073322790e0,-0.001600573e0
, 0.642470600e0,-0.416260100e0,-0.066899570e0, 0.279179500e0
,-0.696605100e0,-0.002860589e0,-0.008098836e0, 3.150547000e0
, 0.007224479e0,-0.705752900e0, 0.534979200e0,-0.079314910e0
,-1.418465000e0
//35
,-0.599905e-16
//36-58
, 0.105840200e0, 0.034317290e0,-0.007022847e0, 0.024955870e0
, 0.042968180e0, 0.746545300e0,-0.291961300e0, 7.294616000e0
,-9.936757000e0,-0.005399808e0,-0.243256700e0, 0.049870160e0
, 0.003733797e0, 1.874951000e0, 0.002168144e0,-0.658716400e0
, 0.000205518e0, 0.009776195e0,-0.020487080e0, 0.015573220e0
, 0.006862415e0,-0.001226752e0, 0.002850908e0};
b=58;
EOSAI.ptr=&EOSAI;
for(a=0;a<=b;a++)
{
EOSAI.ptr->A[a]=B[a]; //此行错误!!!!!!!!!!!!!!
}
}
void array::output(array *ptr)
{
int a,b;
b=58;
for(a=0;a<=b;a++)
{
cout<<A[a]<<"\n";
}
}
错误出在此行: EOSAI.ptr->A[a]=B[a]; 显示是illegal use of floating point
我还写过小程序试过,整数数组就没问题,一旦改成float或者double即使编译时不出错,运行时也会出错:General Protection Fault in module
PS:类成员数组赋值问题好烦啊,有没有大虾给个较好的方法可以批量给类成员double数组赋值,我正把一个fortran程序改写成C++,超多的全局变量需要赋值。大家有没有什么好办法对付Fortran中大量的common变量呀。。。。。