hey guys, i have a project with "Time.h" "Date.h" and "Appointments.h" along with their corresponding .cpp files...within time i have set and get functions for "hour" "minute" and "second" and same style for date...my question is what is the proper way of setting up the "Appointments" constructor...right now within "Appointments.h" i have the "Appointments" constructor looking like this...
public:
Appointments(Date, Time);
and within the "Appointments.cpp" file i have the constructor looking like this...
Appointments::Appointments(Date d, Time t) : Date(d), Time(t)
{
}
and in the main program i am calling it like this...
Inheritance is a much bigger concept that involves creating class instances that are derived from a base class (so the derived class inherits the values of the base). I think you might be confusing constructors with OOP inheritance. What you have is a constuctor default value issue, not an inheritance issue.
That said, the answer to your question "is this proper?" can likely be answered by "does this work?" If it works, it works. Maybe down the road you'll find a better way...
Disch yes it does...i didnt want to copy all the code from every file...so i just focused on my question at hand...thats not all i have in the code...thanks for the replies...
Appointments::Appointments(Date d, Time t) : Date(d), Time(t)
Is Appointments really derived from both Date and Time? If it is then that is probably not a very appropriate use for inheritance. I would consider making Date and Time member variables.