0
我基本上试图初始化一个外部类,以便在我的所有方法中使用它作为成员。从外部类创建成员
我的尝试:
- 初始化在头文件中的成员(错误:
error: 'RECV_PIN_1' is not a type
) - 在构造函数初始化它(现在是不是可以在我的方法)
这里的我缩短的代码:
// Receiver.h
#include "Arduino.h"
#include "IRremote.h"
class Receiver {
public:
Receiver();
void tick();
private:
static const int LED_PIN = 13;
static const int RECV_PIN_1 = 11;
static const int MAX_HEALTH = 1000;
// [..]
IRrecv irrecv(RECV_PIN_1); // this does not work
// [..]
};
// Receiver.cpp
#include "Arduino.h"
#include "IRremote.h"
#include "Receiver.h"
Receiver::Receiver() {
// [..]
}
void Receiver::tick() {
checkHitIndicator();
// if there is a result
if (irrecv.decode(&results)) {
playerHitDetected(10);
// receive the next value
irrecv.resume();
}
}
这会很好,如果somebod你可以解释我是如何以及为什么会达到这个目标的。
嗨,我的编译器不支持第一种方法。 第二个抛出一个神秘的错误'未定义的引用'IRrecv :: IRrecv(int)'' – 2014-11-21 10:18:21
@JulianHollmann:第二个应该是,这是从时间的黎明以来的标准。 – 2014-11-21 10:18:56
我更新了我的评论,第二种方法也不适用于我 – 2014-11-21 10:20:44