Problem with Class Inheritance

Can you guys please check out this code and help me out?

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
#include <iostream>
using namespace std;

class Passport
{
private:
    string PassportNumber;
public:
    Passport(string pnum):PassportNumber(pnum)
    {
        cout<<"The Passport number is:"<<PassportNumber<<endl;
    }
};

class ID:public Passport
{
private:
    string IDnumber;
public:
    ID(string pnum,string IDnum):Passport(pnum),IDnumber(IDnum)
    {
        cout<<"The ID number is:"<<IDnumber;
    }
};

class Person:public ID
{
private:
    string Name;
public:
    Person(string IDnum,string name):ID(IDnum),Name(name)
    {
        cout<<"Person's name is:"<<Name<<endl;
    }
};

int main()
{
    Person john("50","25","John");
    return 0;
}


It works fine up until I created the last class named Person. I can't manage to find out how to connect it with the Passport class. The error that pops out is in line 31 specifically and stating: "no matching function for call to ID::ID(std::string&). I also tried doing 3 string parameters and connecting the first with Passport class but doesn't work also. Maybe there is another way but I don't know how and obviously what I'm trying to do is output all of the needed strings via one derived class.

Thanks in advance.
Last edited on
In

Person(string IDnum,string name):ID(IDnum),Name(name)

ID requires two paramter, but you provide only one.

Change it to:

Person(string pnum,string IDnum,string name):ID(pnum,IDnum),Name(name)


Thank you very much!
Topic archived. No new replies allowed.