C++ return value showing -858993460

C++ return value showing -858993460

In this code:

 Car::Car(int carYearModel, string carMake)
 {
      int yearModel = carYearModel;
      string make = carMake;
      int speed = 0;
 }

You are not assigning to the data members of the Car object. Instead, youre declaring local variables with the same names as the fields, then assigning to those local variables.

To fix this, remove the types:

 Car::Car(int carYearModel, string carMake)
 {
      yearModel = carYearModel;
      make = carMake;
      speed = 0;
 }

Hope this helps!

C++ return value showing -858993460

Leave a Reply

Your email address will not be published.