I am wanting for my object to have a default string value when it is created. In this example, when I create a new Vehicle object, I would like the name variable to be set to "CAR" once it is created.
// Creat an array of vehicles
Vehicle garage[2]; // <- you only have 2 vehicles in your garage
// ie... [0] and [1] are valid indexes
garage[0].setName("Jaguar\0");
garage[1].setName("Audi");
cout << garage[0].getName() << " has " << garage[0].getNumDoors() << " doors" << endl;
cout << garage[1].getName() << endl;
cout << garage[2].getName() << endl; // <- OUT OF BOUNDS, this vehicle
// does not exist!
You are attempting to access a 3rd vehicle when you only have 2. Therefore you are stepping out of bounds of your array and accessing invalid memory.
Change your array to have 3 elements instead of 2.
Vehicle garage[2]; //Create an array of 2 Vehicles, valid indices are [0] and [1]
cout << garage[2].getName() << endl; //Accessing out of bounds. Only luck have prevented crash here.