I figured out how to get operator overloads to work, but how can I define the (overloaded)functions outside the class definition using the scope resolution operator"::". Here is what I am trying to do:
class foo {
public:
foo() : _val(0) {}
foo & operator =(uint8_t);
operator uint8_t(); // << having trouble on this one
private:
uint8_t _val;
};
// got this one working after sometime:
foo & foo::operator = (uint8_t newVal)
{
_val = newVal;
}
// how do I get this one working!?:
uint8_t foo::operator()
{
return _val;
}
void setup()
{
Serial.begin(115200);
foo foo_1;
Serial.println(foo_1); // << expect a 0
foo_1 = 4;
Serial.println(foo_1); // << expect a 4
}
void loop() {}
I want to know the correct way to use operator overloads with the scope resolution operator
one other small question:
what is the difference between this: foo & operator =(uint8_t);
and this? : foo operator =(uint8_t);
they both seem to work
I feel like I confused myself more with the question. I don't even know how to word it correctly. It is very late and I need to sleep, not thinking straight