繁体   English   中英

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

[英]c++: Pass pointer to object within object as argument

如果这很重要,代码适用于 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);
}

尝试编译时,我收到错误消息:“.”之前的预期主表达式。 令牌

发现明显的bug:

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

谢谢你们的帮助:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM