using namespace std;
#include <iostream>
#include "domesticTrip.h"
DomesticTrip::DomesticTrip( const string& inputState, const string& inputTime )
{
State = inputState;
Time = inputTime;
cout << "Some domestic flight information receieved." << endl;
}
DomesticTrip::DomesticTrip( const DomesticTrip& inputDTrip )
{
State = inputDTrip.State;
Time = inputDTrip.Time;
}
The aboving are the 2 .h files and the constructor and copy constructor of class "DomestricTrip". When i compile, i got the error "In constructor 'DomesticTrip......, no matching function for call to 'Trip::Trip()", same error for the copy constructor. can anyone help me?
well, maybe i find the problem. When you've declared the Trip class, you've declared a constructor Trip(parameters) with input values. The compiler, if in a class there isn't ANY Constructor, just use a default constructor. However, since you have declared the constructor Trip(parameters), the compiler doesn't use a default constructor, but use the constructors you have declared.
Then, in the constructor of derivated class DomesticTrip, if you NOT call explicitly the constructor of the Base class, the compiler call a constructor of Base class, and (as mentioned above) you have declared a Constructor for Trip, he search into ALL constructor Trip::Trip(), but you have NOT declared this, and the compiler get an error of 'no matching function of Trip::Trip().
In this case, you can do 2 things:
1) Declare a constructor Trip() into the class Trip;
2) Exsplicitly call the constructor Trip(parameters) from the DomesticTrip Constructor, an example:
1 2 3 4 5 6 7 8 9 10
DomesticTrip( const string& a, const string& b):Trip("","","")
{
// your code
}
//the same for the copy constructor
DomesticTrip (const DomesticTrip& dt):Trip(dt.From,dt.To,dt.Date)
{
/your code
}