inherit: Added comments
This commit is contained in:
parent
defc028857
commit
3c3a83f482
@ -6,18 +6,24 @@ int main ()
|
|||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/* Create generic vehicle type */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int life;
|
int life;
|
||||||
int magic;
|
int magic;
|
||||||
}Vehicle;
|
}Vehicle;
|
||||||
|
|
||||||
|
|
||||||
|
/* Create car, which is a type of vehicle
|
||||||
|
* access vehicle vars by doing car.vehicle.var
|
||||||
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Vehicle vehicle;
|
Vehicle vehicle;
|
||||||
char brand[10];
|
char brand[10];
|
||||||
}Car;
|
}Car;
|
||||||
|
/* We create our first car */
|
||||||
Car myCar;
|
Car myCar;
|
||||||
myCar.vehicle.life = 5;
|
myCar.vehicle.life = 5;
|
||||||
myCar.vehicle.magic = 9;
|
myCar.vehicle.magic = 9;
|
||||||
@ -26,6 +32,8 @@ int main ()
|
|||||||
printf("My car's life is: %d\n" "My car's magic is: %d\n"
|
printf("My car's life is: %d\n" "My car's magic is: %d\n"
|
||||||
"My car's brand is: %s\n\n", myCar.vehicle.life, myCar.vehicle.magic,
|
"My car's brand is: %s\n\n", myCar.vehicle.life, myCar.vehicle.magic,
|
||||||
myCar.brand);
|
myCar.brand);
|
||||||
|
|
||||||
|
/* We create another to show using thing same struct with different values */
|
||||||
Car herCar;
|
Car herCar;
|
||||||
herCar.vehicle.life = 8;
|
herCar.vehicle.life = 8;
|
||||||
herCar.vehicle.magic = 5;
|
herCar.vehicle.magic = 5;
|
||||||
@ -34,7 +42,9 @@ int main ()
|
|||||||
printf("Her car's life is: %d\n" "Her car's magic is: %d\n"
|
printf("Her car's life is: %d\n" "Her car's magic is: %d\n"
|
||||||
"Her car's brand is: %s\n\n", herCar.vehicle.life, herCar.vehicle.magic,
|
"Her car's brand is: %s\n\n", herCar.vehicle.life, herCar.vehicle.magic,
|
||||||
herCar.brand);
|
herCar.brand);
|
||||||
|
/* Here we duplicate herCar (let's say we have a lot of saturns with same stats
|
||||||
|
* But may at some later point lose or gain stats
|
||||||
|
* */
|
||||||
Car herCar2 = herCar;
|
Car herCar2 = herCar;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user