从c ++类

时间:2017-01-10 22:57:59

标签: c++ arduino

有一个带私有数组的简单类和一些从该数组中读取数据的方法

class PinUtils {
  private:
    int pinMatrix[3][3] = {
      {2, LOW, OUTPUT },
      {3, LOW, OUTPUT },
      {4, LOW, OUTPUT }
    };

  public:

    struct PinSetting {
      int pinNumber;
      uint8_t state;    
      int pinType;
    };

    int pinLength(){
      return sizeof(pinMatrix)/sizeof(pinMatrix[0]);
    }

    PinSetting getPinSetting(int index){
      PinSetting pin;
      pin.pinNumber = pinMatrix[index][0];
      pin.state = pinMatrix[index][1];
      pin.pinType = pinMatrix[index][2];

      return pin;
    }    
};

我一直收到像error: 'PinSetting' does not name a type这样的错误,当我创建getPinSetting方法时,类中的结构似乎会生成这个。

示例电话

void setup() {
  Serial.begin(9600);

  PinUtils pin;

  for(int i = 0; i < pin.pinLength(); i++){
    PinUtils::PinSetting pinSetting = pin.getPinSetting(i);

    pinMode(pinSetting.pinNumber, pinSetting.pinType);
    digitalWrite(pinSetting.pinNumber, pinSetting.state);
  }  
}

0 个答案:

没有答案