Using classes with the Arduino
问题 I'm trying to use class objects with the Arduino, but I keep running into problems. All I want to do is declare a class and create an object of that class. What would an example be? 回答1: On Arduino 1.0, this compiles just fine: class A { public: int x; virtual void f() { x=1; } }; class B : public A { public: int y; virtual void f() { x=2; } }; A *a; B *b; const int TEST_PIN = 10; void setup() { a=new A(); b=new B(); pinMode(TEST_PIN,OUTPUT); } void loop() { a->f(); b->f(); digitalWrite(TEST