Please help, default constructor error

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


ParkingLot.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iomanip>
using namespace std;

class ParkingLot
{
protected:
	double amountEarned;
	int numberCars;
public:
	ParkingLot();
	ParkingLot(double);
	virtual void addCar(double);
	virtual void dailyProc();
	double getAmountEarned()
	{ 
		return amountEarned;
	}
	int getNumberCars()
	{ 
		return numberCars; 
	}
};


NorthLot.h
1
2
3
4
5
6
7
8
9
10
11
12
13
#pragma once
#include <iostream>
#include "ParkingLot.h"
#include <string>
using namespace std;

class NorthLot:public ParkingLot
{
public:
	NorthLot(double amountEarned):ParkingLot(amountEarned) {};
	void addCar(double amountEarned);
	void dailyProc();
};


ParkingLot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <string>
#include "ParkingLot.h"
using namespace std;

ParkingLot::ParkingLot()
{
	amountEarned = 0;
	numberCars = 0;
}

ParkingLot::ParkingLot(double aEarned)
{
	amountEarned = aEarned;
	numberCars = 0;

}

void ParkingLot::addCar(double amountPaid)
{
	amountEarned += amountPaid;
	numberCars ++;
}

void ParkingLot::dailyProc()
{
	numberCars = 0;
}





NorthLot.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <string>
#include "NorthLot.h"
using namespace 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();
}


Main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <string>
#include "NorthLot.h"
#include "ParkingLot.h"
using namespace std;

ParkingLot myParkingLot;
NorthLot myNorthLot;

int main()
{
	int choice;
	double amountPaid;
	bool status = true;

	// Displays Menu
	cout << "Parking Lot Menu" << endl;
	cout << "1.Add A Car" << endl;
	cout << "2.Check Number of Cars in Lot" << endl;
	cout << "3.End of Day (Print Statement)" << endl;
	cout << "4.Quit" << endl;
	cin >> choice;

	if(status == true)
	{
		switch(choice)
		{
		case 1:
			cout << "How much did the car pay to park?: ";
			cin >> amountPaid;
			NorthLot::addCar(amountPaid);
			break;
		case 2:
			cout << "There are " << myNorthLot.numberCars << " cars in your parking lot." << endl;
			break;
		case 3:
			NorthLot::dailyProc();
			break;
		case 4:
			cout << "Thank you for watching the parking lot! Good bye!" << endl;
			status = false;
			break;
		}
	}
	

	system("Pause");
	return 0;
}


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).

4) ParkingLot::numberCars cannot access protected

Here is your problem:

myNorthLot.numberCars

Why not call getNumberCars() instead?
Last edited on
Topic archived. No new replies allowed.