请求非类的成员(struct中的struct)

时间:2016-01-07 09:17:51

标签: c++ struct

我从结构中的结构中获取数据时遇到了问题。我正在寻找答案(也在stackoverflow上),但我仍然没有找到它,我不知道它为什么不起作用。

 struct axis
     {
            double pY0, pY1, pY2,
                   Y0,Y1,Y2,Y3;
     };
 struct sensor 
    {
        struct axis X;
        struct axis Y;
        struct axis Z;
    };

struct sensor H;

我想获取或更改传感器内的struct 的数据。

H.X.Y0 = 100.0;

这个错误不断出现。

error: request for member 'X' in 'H', which is of non-class type 'double'

如何正确获取数据以及此方法无效的原因?

编辑(建议后我的原始代码)

struct os
    {
        double pY0;
        double pY1;
        double pY2;
        double Y0;
        double Y1;
        double Y2;
        double Y3;
    };
struct czujnik 
{
    os X;
    os Y;
    os Z;
};
czujnik H1, H2, STJ1, STJ2;

H1.X.Y0 = 0; //Line 2018
H1.X.Y3 = H1.X.Y2;
H1.X.Y2 = H1.X.Y1;
H1.X.Y1 = H1.X.Y0;
H1.X.Y0 =(((double)adcRecv1[i-3]*a3+(double)adcRecv1[i-2]*a2+(double)adcRecv1[i-1]*a1+(double)adcRecv1[i]*a0-b3*H1.X.Y3-b2*H1.X.Y2-b1*H1.X.Y1)/b0);
            limitH=(((double)adcRecv1[i]*a3+(double)adcRecv1[i-1]*a2+(double)adcRecv1[i-2]*a1+(double)adcRecv1[i-3]*a0-b3*H1.X.Y0-b2*H1.X.Y1-b1*H1.X.Y2)/b0);

错误:

2018|error: request for member 'X' in 'H1', which is of non-class type 'double'|
2019|error: request for member 'X' in 'H1', which is of non-class type 'double'|
...

1 个答案:

答案 0 :(得分:2)

在没有看到您的实际代码的情况下,我只是在猜测,但您似乎已经声明了另一个名为H变量,并且该变量的类型为double