I'm trying to sort of follow an example on creating structures and defining data types. Iv'e come up with this small program that i understand most of the program. The part i don't understand is why do i declare model of the type Cars in the class Other. why not just declare it in Cars instead? Why don't i have to specify a data type for model?
struct Cars {
public:
String name;
unsigned long cost;
Cars() : name("mycar"), cost(2222) {}
};
struct Other {
Cars model[10];
public:
} other;
void setup() {
Serial.begin(9600);
}
void loop() {
other.model[0].name = "car1";
other.model[0].cost = 1000;
other.model[1].name = "car2";
other.model[1].cost = 2000;
other.model[2].name = "car3";
other.model[2].cost = 3000;
other.model[3].name = "car4";
other.model[3].cost = 4000;
other.model[4].name = "car5";
other.model[4].cost = 5000;
other.model[5].name = "car6";
other.model[5].cost = 6000;
other.model[6].name = "car7";
other.model[6].cost = 7000;
other.model[7].name = "car8";
other.model[7].cost = 8000;
other.model[8].name = "car9";
other.model[8].cost = 9000;
other.model[9].name = "car10";
other.model[9].cost = 10000;
for (int num = 0; num < 10; num++) {
Serial.println(other.model[num].name);
Serial.println(other.model[num].cost);
}
delay(20000);
}