BuddaZ
December 1, 2018, 6:38pm
1
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
guix
December 1, 2018, 6:41pm
2
PaulRB
December 1, 2018, 6:41pm
3
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.
jimLee
December 2, 2018, 6:20am
5
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
BuddaZ
December 2, 2018, 9:36am
6
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
BuddaZ
December 2, 2018, 9:43am
7
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
BuddaZ
December 2, 2018, 9:57am
8
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
jimLee
December 2, 2018, 4:47pm
10
Well, m is close to a comma.
-jim lee
PaulRB
December 3, 2018, 6:53am
14
Yes, but of course I was very, very drunk.