C++ Gurus

Karl W4KRL W4KRL at arrl.net
Fri Feb 22 17:11:56 CST 2013


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> 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/ 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://amrad.org/pipermail/tacos/attachments/20130222/5cc556d0/attachment.html>


More information about the Tacos mailing list