Hallo,
habe vor langer Zeit mal ein Beispiel zum Klassenübergreifenden Zugriff auf ein und die selbe Variable geschirben und verstehe ihn jetzt selbst nicht mehr vollständig peinlich.
Was macht/bewirkt int A::_a; ??
Vielen Dank!
#define SP Serial.print
#define SPL Serial.println
void RS232(void);
class A{
public:
A() {_a++;}
~A() {_a--;}
static int get() {return _a;}
static void set(int x) {_a = x;}
private:
static int _a;
};
class B{
public:
void set(int x) {A::set(x);}
int get() {return A::get();}
private:
};
int A::_a;
A a;
A b;
A c;
B x;
void setup() {
Serial.begin(115200);
delay(100);
}
void loop() {
RS232();
a.set(5);
RS232();
b.set(6);
RS232();
c.set(8);
RS232();
x.set(12);
SPL(x.get());
delay(1000);
}
void RS232(void){
SPL(A::get());
delay(1000);
}