【发布时间】:2021-12-20 04:01:29
【问题描述】:
我一直在尝试为三维数组分配数据类型,例如,double,但一直收到错误
error: request for member 'size' in 'msd_x', which is of non-class
type 'const sample_type' {aka 'const long unsigned int'}
-> size_t N = msd_x.size();
class mean_square_displacement
{
public:
typedef boost::multi_array_types::size_type sample_type;
//typedef fixed_vector<double, 3> result_type;
typedef double result_type;
result_type operator() (sample_type const& msd_x, sample_type const& msd_y, sample_type const& msd_z) const
{
size_t N = msd_x.size();
result_type msd = 0;
for (unsigned int i = 0; i < N; ++i) {
for (unsigned int j = 0; j < N; ++j) {
auto dr = (msd_x[i+1][j] - msd_x[i][j]) + (msd_y[i+1][j+1] - msd_y[i][j+1]) + (msd_z[i+1][j+2] - msd_z[i][j+2]);
}
// accumulate squared displacements
msd += dr * dr;
}
return msd / N;
}
}
随之而来的是另一个错误:
error: invalid types 'const sample_type {aka const long
unsigned int}[unsigned int]' for array subscript
我猜代码访问数组的方式很好。但它仍然会引发错误。读取的数据代码为double数据类型,如下代码所示:
int main(int argc, char const* argv[])
{
correlator::multi_tau_correlator<double> corr( // TODO replace sample type
nsamples * sampling_interval / 30 trajectory length
, sampling_interval // time resolution at lowest level
, 10
);
// define time correlation functions
auto msd = make_correlation(correlator::mean_square_displacement(), corr);
corr.add_correlation(msd);
// main loop for all coordinates
for (size_t i = 1; i < nsamples; ++i) {
auto position_array = first_rows[i];
// append data to the correlator, which possibly computes some time correlations
corr.sample(position_array);
}
corr.finalise();
return 0;
}
有人指出数据类型有什么问题吗?
【问题讨论】:
-
@TedLyngmo 同样的错误!
-
错误:在'msd_x'中请求成员'size',它是非类类型'const sample_type' {aka 'const long unsigned int'} size_t N = msd_x.size;跨度>
-
我不知道!!!
-
msd_x是sample_type类型,boost::multi_array_types::size_type是unsigned integral类型。所以它只是一些 unsigned int 类型,它是原始类型,而不是对象。因此,它没有成员函数或变量。 -
这也是错误告诉你的:
msd_x的类型是const long unsigned int。