'Hello World' of Inheritance (need help)
Hello,
I need to understand the basic syntax of C++ and object oriented design including inheritance. So I'm trying to compile a sort of template to aid my understanding. This code has multiple problems, and I hardly know where to start with all the errors. I was also perplexed when I thought of creating an instance of the most derived object (the truck class) with all the qualities of the base classes; this particular point-of-confusion is that each constructor (as I wrote them) does not set the instance variables for the upper base classes.
Code:
# include <stdio.h>
# include <stdlib.h>
class Automobile{
protected: /* protected means only derived classes can use directly */
int a;
int b;
public:
Automobile(int a_, int b_){
a = a_;
b = b_;
}
};
Class Truck : Automobile{
protected:
int c;
int d;
public:
Truck(int c_, int d_){
c = c_;
d = d_;
}
};
Class PickUp : Truck{
private:
int e;
int f;
public:
PickUp(int e_, int f_){
e = e_;
f = f_;
}
};
PickUp::print(){
printf("%d %d %d %d %d %d", a,b,c,d,e,f);
}
int main(){
PickUp x(?????);
//I don't understand how to declare a new PickUp object with a,b,c,d,e,f
x.print();
}
Thanks in advance.