No matching function call to class member

Hello to day as the title says i'm getting a "no matching function call to 'ParkedCar::ParkedCar()' error on line 21 col 9 in the ParkingTicket header file and I have no idea why such an error is happening any help would be much appreciated thank you.

Oh and im also kind of getting the same error on line 27 col 9 for the ParkedCar Header "ParkedCar::ParkedCar(std::string, std::string, std::String, std::String, int) again any help will be greatly appreciated.

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  #include<iostream>
#include<cmath>
#include<string>
#include "ParkedCar.h"
#include "ParkingMeter.h"
#include "ParkingTicket.h"
#include "PoliceOfficer.h"

using namespace std;

int main()
{
    string carMake;
    string carModel;
    string carColor;
    string carLicenseNum;  
    int numMinutesParked;                 
    int purchasedParkingMins;             
    string lastName;                      
    string firstName;                 
    string badgeNum; 

    cout << "Enter information for each object below.\n" << endl;
    cout << "CAR:\n" << endl;
    cout << "Make: ";
    cin >> carMake;
    cout << "Model: ";
    cin >> carModel;
    cout << "Color: ";
    cin >> carColor;
    cout << "License Number: ";
    cin >> carLicenseNum;

    do
    {
        cout << "Number of minutes car has been parked: ";
        cin >> numMinutesParked;
    }
    while (numMinutesParked < 0);

    ParkedCar car1(carMake, carModel, carColor, carLicenseNum, numMinutesParked);  
    cout << "\nMETER:\n" << endl; 

    do
    {
        cout << "Number of minutes purchased: ";
        cin >> purchasedParkingMins;
    }
    while (purchasedParkingMins < 0);

    ParkingMeter meter1(purchasedParkingMins);

    cout << "\nPOLICE OFFICER:\n" << endl;          
    cout << "First Name: ";
    cin >> firstName;
    cout << "Last Name: ";
    cin >> lastName;
    cout << "Badge Number: ";
    cin >> badgeNum;

    PoliceOfficer officer1(lastName, firstName, badgeNum);     

    if (officer1.isTicketNeccessary(car1, meter1) == true)        
    {
        ParkingTicket ticket1(car1, meter1, officer1);           
        ticket1.print();                                         
    }
    else                                                         
    {
        cout << "\n* No ticket issued. *" << endl;
    }

    return 0;
}


ParkedCar.h
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
  #ifndef PARKINGCAR_H
#define PARKINGCAR_H

#include <iostream>

using namespace std;

string carMake;

class ParkedCar
{  

			private:
            string carMake;
            string carModel;
            string carColor;
            string carLicenseNum;
            int numMinutesParked;
            
        	public:
            //carMake = "";
            //carModel = "";
            //carColor = "";
            //carLicenseNum = "";
            //numMinutesParked = 0;

        ParkedCar(string cMake, string cModel, string cColor, string cLicenseNum, int cNumMinParked)
        {
            carMake = cMake;
            carModel = cModel;
            carColor = cColor;
            carLicenseNum = cLicenseNum;
            numMinutesParked = cNumMinParked;
        }

        int getNumParkedMinutes() const
        {
            return numMinutesParked;
        }

        void print() 
        {
            cout << "- Car -\n" << endl;
            cout << "Make: " << carMake << endl;
            cout << "Model: " << carModel << endl;
            cout << "Color: " << carColor << endl;
            cout << "License Number: " << carLicenseNum << endl;
        }
};

#endif 


ParkingMeter.h
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
  #ifndef PARKINGMETER_H
#define PARKINGMETER_H

#include <iostream>

using namespace std;

class ParkingMeter
{
    private:
        int purchasedParkingMins;                     

    public:
        ParkingMeter()                                
        {
            purchasedParkingMins = 0;
        }

        ParkingMeter(int purchasedMinutes)            
        {
            purchasedParkingMins = purchasedMinutes;
        }

        int getPurchasedParkingMins() const           
        {
            return purchasedParkingMins;
        }

        void print()                                  
        {
            cout << "- Meter -\n" << endl;
            cout << "Number of minutes purchased : " << purchasedParkingMins << endl;
        }
};
#endif 


PoliceOfficer.h
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
53
54
55
  #ifndef POLICEOFFICER_H
#define POLICEOFFICER_H

#include <iostream>
#include <string>
#include <vector>
#include "ParkedCar.h"
#include "ParkingMeter.h"

using namespace std;

class PoliceOfficer
{
    private:
        string lastName;                        
        string firstName;                       
        string badgeNum;                        

    public:
        PoliceOfficer()                         
        {
            lastName = "";
            firstName = "";
            badgeNum = "";
        }

        PoliceOfficer(string lName, string fName, string bNum)         
        {
            lastName = lName;
            firstName = fName;
            badgeNum = bNum;
        }

        bool isTicketNeccessary(ParkedCar& c, ParkingMeter& m)       
        {
            if ((m.getPurchasedParkingMins() - c.getNumParkedMinutes()) < 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        void print()                                    
        {
            cout << "- Police Officer -\n" << endl;
            cout << "First Name: " << firstName << endl;
            cout << "Last Name: " << lastName << endl;
            cout << "Badge Number: " << badgeNum << endl;
        }
};

#endif 


ParkingTicket.h
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
  #ifndef PARKINGTICKET_H
#define PARKINGTICKET_H

#include <iostream>
#include "ParkedCar.h"
#include "ParkingMeter.h"
#include "PoliceOfficer.h"

using namespace std;

class ParkingTicket
{
    private:
        ParkedCar car;                    
        ParkingMeter meter;               
        PoliceOfficer officer;            
        int fineAmount;                   

    public:
        ParkingTicket(ParkedCar &carT, ParkingMeter &meterT, PoliceOfficer &officerT)         
        {
            car = carT;                              
            meter = meterT;
            officer = officerT;
            fineAmount = calcFineAmount();
        }

        int calcFineAmount()               
        {
            return (25 + 10 * (ceil((car.getNumParkedMinutes()- meter.getPurchasedParkingMins())/60.0) - 1));
        }

        void print()        
        {
            cout << "\n\n***** TICKET INFORMATION *****" << endl;
            cout << "-------------------------------------" << endl;
            car.print();
            cout << "-------------------------------------" << endl;
            officer.print();
            cout << "-------------------------------------" << endl;
            cout << "- Fine -\n\n" << "Amount: $" << fineAmount << endl;
            cout << "-------------------------------------" << endl;
        }
};

#endif 
Last edited on
I think you're missing a default constructor in ParkedCar.h that takes no arguments.
OMG thank you i completely forgot i had commented them out to later make a constructor lmao im an idiot thank.

PS. im laughing so hard right now lmao added this and now it works as intended thanks again!!!

1
2
3
4
5
6
7
8
   ParkedCar()                         
        {
            carMake = "";
            carModel = "";
            carColor = "";
            carLicenseNum = "";
            numMinutesParked = 0;
        }
Topic archived. No new replies allowed.