johncc:
A class is defined in an .h file.If the variable is to be a class variable, it is defined within the class.
Are you asking when should a variable be a class variable? If so, that is one of the routine continuous questions of Object Oriented Design.
If you're asking whether the class variable should be public or private (or protected--but no need to go there here), that's another one but the short answer I would say is "public if you want it to be part of the interface" and "private if it's part of the implementation". Another way to say might be
I'm the Object. My variable will be public if I don't mind my users accessing me without me knowing it. If I do mind, I will instead do something like this
class Me{
private:
int myVariablePPM; // e.g. stored as part-per-million
public
int myVariablePpm(){ return myVariable; } // this way I "know it" when someone tries to access me
int myVariablePct(){ return myVariable/10000; } // or even pretend to have variables that I don't
};
But this is just nuts and bolts OO.... not sure if its what you're asking :) Cheers, John
John,
Nice writeup. Its funny that before I read your reply I did some studying on classes and objects. I realize now that I need to understand OO better to build effective Arduino libraries.