C++ inheritance and UML files// I keep an error saying no matching function for call Passenger:Passenger

//Person.h

#include "Person.h"
#include <iostream>
#include <string>
using namespace std;
Person::Person()
{
id=0;
name=" ";
address=" ";
}
void Person::setPerson(int id1,string name1,string address1)
{
id=id1;
name=name1;
address=address1;
}

int Person::getId()
{
return id;
}
//void Person::setId(int pid)
//{
// pid=id;
//}
string Person::getName()
{
return name;
}
//void Person::setName(string sn)
//{
// sn=name;
//}
string Person::getAddress()
{
return address;
}
//void Person::setAddress(string add)
//{
// add=address;
//}
void Person::printPerson()
{
cout<<"The ID of the person is "<<id<<endl;
cout<<"The name of the person is "<<name<<endl;
cout<<"The address of the person is "<<address<<endl;
}

Person::~Person()
{
}





Person.cpp
#ifndef PERSON_H
#define PERSON_H
#include <iostream>
#include <string>
using namespace std;

class Person
{
public:
Person();
void setPerson(int,string,string);
~Person();
int getId();
//void setId(int);
string getName();
// void setName(string);
string getAddress();
//void setAddress(string);
void printPerson();

protected:
int id;
string name;
string address;
};

#endif // PERSON_H




//Passenger.h
#ifndef PASSENGER_H
#define PASSENGER_H
#include "Person.h"
#include <iostream>
#include <string>

class Passenger : public Person
{
public:

~Passenger();
Passenger(int=0,string="",string="",string="");
//void setPassenger(string);
string getFrequentFlyerPlan();
//void setFrequentFlyerPlan(string);
void printPerson();

private:
string frequentflyerplan;
};

#endif // PASSENGER_H






//Passenger.cpp file
#include "Passenger.h"
#include "Person.h"
#include <iostream>
#include <string>
using namespace std;
//Passenger::Passenger()
//{
// frequentflyerplan=" ";
//}
Passenger::Passenger(int id1,string name1,string address1,string FFP1):Person(id1,name1,address1)
{
frequentflyerplan=FFP1;

}


string Passenger::getFrequentFlyerPlan()
{
return frequentflyerplan;
}

void Passenger::printPerson()
{
cout<<"What is your frequent flyer plan? "<<frequentflyerplan<<endl;
Person::printPerson();
}

Passenger::~Passenger()
{

}
Last edited on
if you don't understand the error message, then post it verbatim
|| foo.cpp: In constructor ‘Passenger::Passenger(int, std::__cxx11::string, std::__cxx11::string, std::__cxx11::string)’:
foo.cpp|108 col 34| error: no matching function for call to ‘Person::Person(int&, std::__cxx11::string&, std::__cxx11::string&)’
foo.cpp|34 col 1| note: candidate: ‘Person::Person()’
foo.cpp|34 col 1| note:   candidate expects 0 arguments, 3 provided
foo.cpp|8 col 7| note: candidate: ‘Person::Person(const Person&)’
foo.cpp|8 col 7| note:   candidate expects 1 argument, 3 provided


1
2
3
4
Passenger::Passenger(int id1, string name1, string address1, string FFP1)
    : Person(id1, name1, address1) {
	frequentflyerplan = FFP1;
}
There you are trying to call Person constructor with three arguments
however, you do not have such constructor
Topic archived. No new replies allowed.