declaring object

I have a code with classes that compiles fine until I declare object for class Journey in line 25.
When I add an object there I get:
line 19: no matching function for call to Vehicle::Vehicle
line 15: candidate expects 8 arguments
line 6: candidate expects 1 arguments, 0 provided


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
75
76
77
78
79
80
81
82
83
#include <iostream>
using namespace std;

const unsigned short components = 100;

class Vehicle{
protected:
    string type, regNumber, make, model;
    float kilomiters;
    unsigned short capacity;
    char wheelchair;
    bool booked;
public:
    void changeStatus(){booked = true;};
    Vehicle (string t, string reg, string mak, string mod, float kil, unsigned short cap, char wheel, bool b){type = t; regNumber = reg; make = mak;
    model = mod; kilomiters = kil; capacity = cap; wheelchair = wheel; booked = b;};
};

class Journey: public Vehicle{
protected:
    string fareID, returnTime;
    float length;
public:
    bool checkAvalibility();
};

class Person{
protected:
    string name, phoneNo;
public:

};

class Customer: virtual public Person{
protected:
    string source, destination, pickUpTime;
    unsigned short numOfPeople;
    bool wheelChair;
public:
    void getDetails();
};

class Driver: virtual public Person{
protected:
    string idNum, address, licenceDate,licenceType;
    float kilomiters;
    bool booked;
public:
    void changeStatus(){booked = true;};
    Driver (string nam, string ph, string id, string add, string licenceD, string licenceT, float kil, bool b){name = nam; phoneNo = ph; idNum = id;
    address = add; licenceDate = licenceD; licenceType = licenceT; kilomiters = kil; booked = b;};
};
class Report: public Journey, public Customer, public Driver{
private:
    float totalRevenueVehicle, totalRevenueDriver, totalKilomitersDriver, totalKilomitersVehicle;
public:
    void printReport();
    float calculateRevenue();
    float calculateKilomiters();
};



int main(){
    Driver driver1("Tom Daly", "087-6543210", "1234567A", "14 Green St., Cork", "12/08/2008", "B", 23231, false);
    Driver driver2("Anne O'Brien", "086-5432109", "2345678B", "\"Beach View\", Kinsale", "09/12/2011", "D", 11980, false);
    Driver driver3("James Twomey", "085-4321098", "3456789B", "14, French St., Cork", "14/11/2010", "D1", 18414, false);
    Driver driver4("Mary O'Neill", "089-8765432", "4567890C", "23 Castle Road, Youghal", "11/02/2014", "B", 12669, false);
    Driver driver5("Brendan Brown", "083-2109876", "5678901D", "98 Nuns Walk, Cork", "01/04/2007", "D", 23864, false);
    Driver driver6("Vincent Coy", "087-8901234", "6789012E", "\"Green Valley\", Cobh", "03/04/1998", "D1", 3416, false);
    Vehicle vehicle1("Taxi", "12 C 4956", "Hyundai", "i30 Tourer", 65172, 4, 'Y', false);
    Vehicle vehicle2("Taxi", "14 C 89365", "Ford", "Mondeo", 33892, 4, 'Y', false);
    Vehicle vehicle3("Taxi", "15 C 46046", "VW", "Passat", 23897, 4, 'Y', false);
    Vehicle vehicle4("Taxi", "14 C 38492", "Nissan", "Primera", 29418, 4, 'Y', false);
    Vehicle vehicle5("Taxi", "10 C 99393", "Skoda", "Octavia", 29418, 4, 'Y', false);
    Vehicle vehicle6("Taxi", "15 C 2379", "Seat", "Toledo", 12812, 4, 'Y', false);
    Vehicle vehicle7("Bus", "10 C 37209", "Ace", "Cougar", 28786, 48, 'Y', false);
    Vehicle vehicle8("Bus", "11 C 882", "Daimler", "Fleetline", 68893, 48, 'N', false);
    Vehicle vehicle9("Minibus", "14 C 23908", "Ford", "Transit", 18827, 16, 'Y', false);
    Vehicle vehicle10("Minibus", "10 C 831", "Fiat", "Ducato", 31986, 16, 'Y', false);
    Vehicle vehicle11("Minibus", "13 C 82677", "Mercedes-Benz", "Mercedes-Benzario", 18567, 20, 'N', false);
return 0;
}


I know I have a constructor for vehicle and Journey is inheriting from Vehicle
but I don't know how to solve this

help please
no matching function for call to Vehicle::Vehicle


Something wants to use a constructor that doesn't exist. Looks like the "default" constructor (i.e. the constructor that takes no arguments). You haven't created a constructor for Vehicle that takes no arguments, so that makes sense. Tell your Journey object which Vehicle constructor to use: http://stackoverflow.com/questions/3714162/class-inherited-from-class-without-default-constructor

As an aside, I'm a little concerned that a Report is a kind of Vehicle.
Last edited on
@peter, it compiles fine the way it is, but if you stick any object in line 25 thats where the errors will occur

@moschops the link you gave me is showing how to make one class inherit constructor from another one, but i want my class Journey not to inherit a constructor form class Vehicle
the link you gave me is showing how to make one class inherit constructor from another one

No it isn't. Read it again, or maybe this one covering the same problem in fewer words will be easier to understand: http://stackoverflow.com/questions/4352169/default-constructor-for-an-inherited-class

When you are creating an actual object of type journey, its constructor will call a constructor of Vehicle. This is what derived classes do. They call a constructor of their parent.

You need to tell it which constructor to call. Right now, you haven't told it which constructor to call, so it's trying to call Vehicle::Vehicle(), which doesn't exist.


Peter is right, though. The code above compiles fine, and adding an object on line 25 makes no difference. It still compiles fine, right up until you try to create an actual Journey object. Is that what you meant? that you're creating a Journey object on line 25? After that } ?
Last edited on
yes after doing this in line 25
}object1;

I get this errors
Well then the fix is explained above.
Topic archived. No new replies allowed.