c ++:将指向对象内的对象的指针作为参数传递

时间:2016-04-06 13:24:07

标签: c++ arduino

如果重要,代码适用于Arduino ......

class Xbee{
  public:
    Xbee(SoftwareSerial *xbeeSerial, SoftwareSerial *debugPrinter);
};

class localXbee : public Xbee{
  public:
    localXbee(SoftwareSerial *xbeeSerial, SoftwareSerial *debugPrinter);
    void addRemoteXbee(remoteXbee *newBee, byte index);
};

class remoteXbee : public Xbee{
  public:
    remoteXbee(long AddressLSB, SoftwareSerial *xbeeSerial, SoftwareSerial *debugPrinter);

class xbeeThermostat{
  public:
    xbeeThermostat(long AddressLSB, SoftwareSerial *xbeeSerial, SoftwareSerial *debugPrinter);
    remoteXbee thermoBee;
};

那么当remoteXbee对象在xbeeThermostat对象中时,如何调用localXbee对象中的addRemoteXbee函数?

localXbee coordinator(&xbeeSerial, &debugPrinter);
xbeeThermostat thermostat(0x40BE4864, &xbeeSerial, &debugPrinter);

void setup(){
    coordinator.addRemoteXbee(&xbeeThermostat.thermoBee,0);
}

尝试编译时,我收到错误消息: 在''之前预期的初级表达。令牌

1 个答案:

答案 0 :(得分:0)

发现了明显的错误:

void setup(){
    coordinator.addRemoteXbee(&thermostat.thermoBee,0);
}

感谢帮助人员:)