Inside separate .h
files:
class Appt{
public:
Appt(string location, string individual, DaTime whenwhere);
private:
string individual;
string location;
DaTime whenwhere; // I thought this would initialize it
DaTime a;
}
class DaTime{
public:
DaTime(Day day, Time start, Time end); // Day is enum, Time is class
private:
int duration;
Day day;
Time start;
Time end;
}
Inside separate .cc
files:
// class Appt constructor
Appt::Appt(string location, string individual, DaTime whenwhere)
{
a_SetLocation(location);
a_SetIndividual(individual);
DaTime a(whenwhere); // THE LINE IN QUESTION
}
// class DaTime constructor
DaTime::DaTime(Day day, Time start, Time end)
{
dt_SetDay(day);
dt_SetStart(start);
dt_SetEnd(end);
}
inside main()
:
/* Creating random variables for use in our classes */
string loc1 = "B";
string p1 = "A";
/* Creating instances of our classes */
Time t1(8, 5), t2(8, 30);
DaTime dt1('m', t1, t2);
Appt A1(loc1, p1, dt1);
My question is if there is a clean way for me to call DaTime
s constructor inside of Appt
? I know this way wouldn't work because my instance of DaTime
, a
would die after the constructor
was finished.
EDIT: The error I am getting is:
In constructor ‘Appt::Appt(std::string, std::string, DaTime)’:
appt.cc: error: no matching function for call to ‘DaTime::DaTime()’
Appt::Appt(string location, string individual, DaTime when where)
In file included from appt.h:15:0,
from appt.cc:15:
class.h:note: DaTime::DaTime(Day, Time, Time)
DaTime(Day day, Time start, Time end);
^
note: candidate expects 3 arguments, 0 provided
note: DaTime::DaTime(const DaTime&)