I'm in a basic C++ programming class and I am looking for some help on my final program. It is a basic parent, child class.
I have 4 errors, but I believe they are based off the same thing
1) NorthLot has no appropriate default constructor available
2) NorthLot:dailyProc() illegal call of non-static member
3) NorthLot::addCar() same thing as above
4) ParkingLot::numberCars cannot access protected
^-- even though i have a getNumberCars function
#include <iostream>
#include <string>
#include "NorthLot.h"
usingnamespace std;
void NorthLot::addCar(double amountPaid)
{
if(amountPaid < 0)
{
cout << "Please restart and enter an amount greater than 0" << endl;
}
else
{
ParkingLot::addCar(amountPaid);
}
}
void NorthLot::dailyProc()
{
double ownAmount;
double businessAmount;
ownAmount = (amountEarned * .6);
businessAmount = amountEarned - ownAmount;
cout << "Thanks for watching the North Parking Lot today!" << endl;
cout << "A total of " << numberCars << " cars have parked in the lot today." << endl;
cout << endl;
cout << "You will pocket $" << ownAmount << ". (60% of total)" << endl;
cout << "You need to give $" << businessAmount << " to the business you are watching. (40% of total)" << endl;
ParkingLot::dailyProc();
}
1) NorthLot has no appropriate default constructor available
A default constructor is declared like this:
1 2 3 4 5 6 7
class myClass
{
public:
myClass() //this is the default constructor of myClass
{
}
};
Look at NorthLot's definition. See how you need to change it using the above example.
2) NorthLot:dailyProc() illegal call of non-static member
This is the part that's giving you trouble:
NorthLot::dailyProc();
You can only access dailyProc() like that if it has been declared static. You don't want to do that in this case. The call to dailyProc() should be attached to an instance of NorthLot (you have already declared one).
3) NorthLot::addCar() same thing as above
This is the part that's giving you trouble:
NorthLot::addCar(amountPaid);
This call to addCar() should be attached to an instance of NorthLot (you have already declared one).