If you want a constructor to take 6 arguments, then you'll need to declare with that many arguments. Then, using the initialization list, you can forward arguments to the parent's constructor.
There are also other errors, like needing to use public for normal "is-a" inheritance (or the protected members of the grand-parent class will still be unavailable.
Code:
# include <stdio.h>
# include <stdlib.h>
class Automobile
{
protected: /* protected means only derived classes can directly use */
int a;
int b;
public:
Automobile(int a_, int b_)
{
a = a_;
b = b_;
}
};
class Truck : public Automobile //use public inheritance, or Automobile's a and b won't be accessible to classes derived from this
{
protected:
int c;
int d;
public:
Truck(int a_, int b_, int c_, int d_):
Automobile(a_, b_) //invoke parent constructor with arguments
{
c = c_;
d = d_;
}
};
class PickUp : public Truck //use public inheritance
{
private:
int e;
int f;
public:
PickUp(int a_, int b_, int c_, int d_, int e_, int f_):
Truck(a_, b_, c_, d_) //invoke its constructor
{
e = e_;
f = f_;
}
void print(); //needs to be declared
};
void PickUp::print() //has return type
{
printf("%d %d %d %d %d %d", a,b,c,d,e,f);
}
int main()
{
PickUp x(1, 2, 3, 4, 5, 6);
x.print();
}