Guten Tag zusammen,
beim Durchstoebern einiger Bibliotheken fuer den Arduino kam mir des Oefteren
der Objekt/Element Zugriff mittels "this Zeigers" in die Quere.
Daher eine allgemeine Frage an Euch:
Verwendet Ihr bei einem "simplen" Zugriff auf ein Element eines Objekts "this->"?
class Test_class {
private:
int int_bla;
public:
int get_bla()...; //angepasst an mit this/ohne this
};
//ohne this
int Test_class::get_bla() const {
return int_bla;
}
//mit this
int Test_class::get_bla() const {
return this->int_bla;
}
Ausfuehrliches Bsp:
class test_class
{
private:
static const int con_int = 21;
static constexpr float con_float = 1.23;
int bla_int;
float bla_float;
public:
void begin(const int set_i, const float set_f);
int get_con_int();
float get_con_float();
int get_int();
float get_float();
};
//Konstruktoren
void test_class::begin(const int set_i, const float set_f)
{
bla_int = set_i;
//this->bla_int = set_i;
this->bla_float = set_f;
}
int test_class::get_con_int()
{
return this->con_int;
}
float test_class::get_con_float()
{
return con_float;
//return this->con_float;
}
int test_class::get_int()
{
return this->bla_int;
}
float test_class::get_float()
{
return this->bla_float;
}
//Objekt(e)
test_class test_obj;
void setup()
{
Serial.begin(19200); while (!Serial) {}
test_obj.begin(31, 2.34);
Serial.print(F("get_con_int()\t")); Serial.println(test_obj.get_con_int());
Serial.print(F("get_con_float()\t")); Serial.println(test_obj.get_con_float());
Serial.print(F("get_int()\t")); Serial.println(test_obj.get_int());
Serial.print(F("get_float()\t")); Serial.println(test_obj.get_float());
}
void loop() {}
schoenes WE
grillgemuese