C++ Gurus
Mike O'Dell
mo at ccr.org
Fri Feb 22 22:41:27 CST 2013
it's not that it will "change in all objects",
there is only ONE set of the class variables
that is (logically) "shared" by all the instances.
the code in the methods references
that one copy for the class variables,
while the set of instance variables are unique
per instance.
class variables are really "global variables" that are seen
only by the methods of that class and like global
variables in C, there is only one instantiation of each
of the class variables.
does this help?
-mo
On 2/22/13 6:11 PM, Karl W4KRL wrote:
>
> Jason,
>
> I think that is pretty much what I am looking for. I will give it a
> try. If a variable is, say, public: int var then each object will have
> its own var. But if it is private: static int var then if var changes
> in the class it will change in all objects? How do I implement a
> method that will change the class variable?
>
> Thanks,
>
> Karl
>
> *From:*Jason Wright [mailto:jason at thought.net]
> *Sent:* Friday, February 22, 2013 5:37 PM
> *To:* Karl W4KRL
> *Cc:* tacos
> *Subject:* Re: C++ Gurus
>
> On Fri, Feb 22, 2013 at 3:29 PM, Karl W4KRL <W4KRL at arrl.net
> <mailto:W4KRL at arrl.net>> wrote:
>
> I am creating a Button class to use with a touchscreen display.
> The touchscreen is actually a separate device glued to the front
> of the LCD display. The class must translate the touchscreen
> coordinates to the LCD coordinates to test if the user is touching
> the screen at the button position.
>
> Each button has several unique visible properties like position,
> size and color. The parameters needed to translate the touchscreen
> to LCD are the same for each button. However, they are unknown
> with precision until the screen is calibrated. I do have some
> generic parameters that are close enough without calibration.
>
> How do I get the touchscreen parameters into the class so that all
> objects will be able to do the translation? At the moment the
> generic parameters are hard coded into the class constructor. Is
> there a clever way to get the parameters into the class?
>
> I think what you're looking for are static class variables [1].
>
> If you declare them as:
>
> private: static int _tXmin, _tXmax, _tYmin, _tYmax, _tZmin, _tZmax;
> // touch plate ADC readings
>
> Then that should be visible in all instances of the class. Marking
> them protected or public has the usual effects on child classes. A
> change in the variable in one instances affects them all (they are
> class variables now). Is this what you're looking for, or did I
> misunderstand?
>
> [1] http://www.learncpp.com/cpp-tutorial/811-static-member-variables/
>
>
>
> _______________________________________________
> Tacos mailing list
> Tacos at amrad.org
> https://amrad.org/mailman/listinfo/tacos
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://amrad.org/pipermail/tacos/attachments/20130222/0e20c891/attachment.html>
More information about the Tacos
mailing list