How can i use subvariables?

Quick question... how would one go about storing a set of variables in a subvariable... probably the wrong terminology for it.

so for example... I want to store an

X coord Y coord Width Height

Under a set...

Like if i were to call

button1.X

and have it return the X value

Hello,

Use a struct, or a class :)

http://www.cplusplus.com/doc/tutorial/structures http://www.cplusplus.com/doc/tutorial/classes

2 ways.

A "struct". This is the older C way, but often still appropriate.

A "class". This is the newer C++ way. The door to the world of object orientation.

variables in a subvariable... probably the wrong terminology

In a struct, they are normally referred to as "fields". In a class, they are called "attributes".

The difference between ‘struct’ and ‘class’ is that until otherwise stated, members are ‘public:’ in struct and ‘private:’ in class. If you use a class, put the line “public:” at the top so code outside the class declaration can use the data.

class rectangle {

   public:
        rectangle(int inX,int inY,int inWm int inH);
        ~rectangle(void);

   int X coord;
   int Y coord;
   int Width;
   int Height;
};

And you just opened up Pandora's box..

Welcome to c++

-jim lee

jimLee: ``` class rectangle {

  public:         rectangle(int inX,int inY,int inWm int inH);         ~rectangle(void);

  int X coord;   int Y coord;   int Width;   int Height; };



And you just opened up Pandora's box..

Welcome to c++

-jim lee

THANK YOU! Ive been playing with arduino and x for a long time now... but have never needed a structure... it helps to know the proper term lol

johnwasser: The difference between 'struct' and 'class' is that until otherwise stated, members are 'public:' in struct and 'private:' in class. If you use a class, put the line "public:" at the top so code outside the class declaration can use the data.

Huh... thanks for the tip... thats actually really helpful to know

guix: Hello,

Use a struct, or a class :)

http://www.cplusplus.com/doc/tutorial/structures http://www.cplusplus.com/doc/tutorial/classes

Yes! Knowledge links!!

I... probably should have thought of looking in the programming base instead of exclusively on arduino lol...

THANK YOU!!

rectangle(int inX,int inY,int inWm int inH);

And you just opened up Pandora’s box…

But not until you fix the missing comma

Well, m is close to a comma.

-jim lee

jimLee:
Well, m is close to a comma.

-jim lee

Close enough for jazz :slight_smile:

UKHeliBob: Close enough for jazz :)

"Nice!..."

PaulRB: "Nice!..."

Fast Show reference?

Yes, but of course I was very, very drunk.