I've have been away from C++ for a long time so I am rusty to say the least. However, I'm trying to use friend classes to share data/functions but I cannot get things to work. I've distilled my code down to the following example:
class HelperClass;
class MainClass {
public:
friend class HelperClass;
// protected:
int a = 1;
};
class HelperClass {
public:
};
MainClass mClass;
HelperClass hClass;
void setup() {
Serial.begin(115200);
delay(1000);
Serial.println(mClass.a); // This compiles
Serial.println(hClass.a); // This doesn't error: 'class HelperClass' has no member named 'a'
}
void loop() {
// put your main code here, to run repeatedly:
}
Anyone know why?