I read that a structure is the same as a class but its variables are public by default
Not exactly. A struct is a C feature. A C++ struct can have methods, but that’s rather unusual. A C struct can not.
A class without methods is a waste of time.
and I also have to download a library for this functionality.
I thought the constructor could be used to initialize variables in the object at the top of the class hierarchy?
The construct can be used to initialize variables. What this has to do with “the top of the class hierarchy” or what that means is not clear.
So each Menu class object will have a myname variable which is created on initialization?
Not unless you define a variable in the class to hold the value.
Please explain what I am trying to do versus what should be done.
How can I explain what you are trying to do when you can’t?
I thought variables were just instances of objects from the data type class?
Some are. Some aren’t. It depends on the variable type.
int i = 0;
i is not an instance of a class.
Blob *pPile = new Blob();
pPile is an instance of the class Blob;
heap is an object of the Blob class.
This saves the argument pin to a private variable _pin, but I want the variable to be accessable
It does, and _pin IS accessible from all member functions. Why do you think it isn’t?
I will use the struct library if I must, but would like to learn a bit about classes as well.
There is no struct library. Learning about classes is good. Stumbling along clueless isn’t. Get a C++ book. Read it. Study the examples.
So all I had to do was:
But that is wrong. myname should not be a String and it should not be public.
What does myStuff return?
Pancakes with maple syrup.
The question doesn’t make sense, any more than the answer does. An array declaration doesn’t return anything.
Can I do e.g myStuff.name and mystuff.item1?
No. myStuff is an array with three elements. The elements are numbered 0, 1, and 2. You could do:
How can I accomplish this using classes (for education only), is it a class inside a class?
Stuff( char *someName);
In the above line …, what is Stuff and myStuff and where are they defined?
“Stuff” is an alias for “struct stuff”. myStuff is an array of objects of type Stuff (or struct stuff). Where they are defined should be obvious.
As soon as I include menu1.item1=13;
I get: expected constructor, destructor, or type conversion before “.” token
Executable code needs to be in functions.
typedef struct stuff Stuff;
Binary sketch size: 678 bytes (of a 258,048 byte maximum)
when the board type is Mega.