What I want here is for different classes (declared in the same scope) to be able to access each other's public methods and properties. I have spent several days already looking around online and trying to find any way to do this, and I have not found any way that works.
I have found at least a couple ways of passing a class by reference (putting & after the class type, and putting & before the instance name in the function prototype) but neither of those makes any difference. One attempt at this allowed me to access the first-declared-property of the target class, but no other properties or methods were usable remotely.***
A lot of the examples I found online will compile without errors, but they simply don't work. I could set an initial property by the class that it was in, and then try to serial.print it from another class, and the result is completely incorrect--but is consistently incorrect--leading me to believe that the referencing is getting mangled somewhere along the way. (Also for the reason *** noted above)
There are lots of posts all around that claim there is a way to do this just by passing a reference, but I can not get any of their examples to work, or their examples are a highly specialized particular situation that wasn't helpful to what I want to do.
This example on stackexchange:
Is specific to Arduino, is relatively recent and says to create another class that includes references for all the other instances you have, and then put a reference to that into all the other classes. I tried that and could not get it to work either. But if the reference-passing doesn't work right, that isn't real surprising.
The exact problem is that in the Arduino IDE, any one object does not recognize any other class that isn't passed into it, even ones declared in the same scope. I am not a professional programmer but I have some education and some years experience with coding in a few languages, and have not run across this problem with other platforms and languages.
I could just copy an external object to an internal one in a different class, but it seems like there should be some way to do this by reference???
There are a few posts (some from here) from ~2010 and earlier, mentioning that the preprocessor that the Arduino IDE compiler uses is set up in an unconventional way, that happens to break this particular functionality. Is this still true? There are a LOT of posts asking about this exact problem, and many of them are about the Arduino IDE....
Here is a simple example sketch, that doesn't work:
Is it possible to do this by passing values? Or is pointers the only option?