A
ali
Hi,
I am new to C++ and trying to understand how to work on Inheritance
and Operator overloading. I understand that the derived class can pass
the base class constructor in its constructor definition as following
code:
Car::Car(int id, int colorID, int type):Vehicle(id, colorID)
{
this->type = type;
}
What I am having difficulty with, is, how do I call the base class
constructor when writing the copy constructor for the derived class?
Example:
Car::Car(const Car &rhs)
{
//my code
}
Can I just add it as:
Car::Car(const Car &rhs):Vehicle(rhs.getID, rhs.getColor)
{
this->type = rhs.type;
}
I'm not sure of the above code copy constructor code accuracy, but
would appreciate some guidance.
Thank you!
Ali
I am new to C++ and trying to understand how to work on Inheritance
and Operator overloading. I understand that the derived class can pass
the base class constructor in its constructor definition as following
code:
Car::Car(int id, int colorID, int type):Vehicle(id, colorID)
{
this->type = type;
}
What I am having difficulty with, is, how do I call the base class
constructor when writing the copy constructor for the derived class?
Example:
Car::Car(const Car &rhs)
{
//my code
}
Can I just add it as:
Car::Car(const Car &rhs):Vehicle(rhs.getID, rhs.getColor)
{
this->type = rhs.type;
}
I'm not sure of the above code copy constructor code accuracy, but
would appreciate some guidance.
Thank you!
Ali