hey guys i hope that you are doing well , i have a question here its about C++ i have a question if we have a derived class, can we use a constructor to initialize inherited attributes in listed constructors method like in the code bellow :
#include <string>
#include <iostream>
using namespace std;
class Vehicle {
protected:
string type;
string brand;
int speed = 90;
public:
void getVehicleInfo() {
cout << "Vehicle Informations:\n";
cout << "Type: " << type << "\n";
cout << "Speed: " << speed << " km/h\n";
}
};
class Car : public Vehicle {
public:
Car() : type = ("Voiture") , speed (204) {
cout << "Car set successfully ! ";
}
void setSpeed (int vitesse){
if (vitesse < 500 || vitesse > 0)
speed = vitesse;
}
};
int main() {
Car VW;
//VW.setSpeed(90);
VW.getVehicleInfo();
return 0 ;
}
it gives an error in line 22.