i have two classes
//Event class
class Event
{
public:
Event();
Event(const Time & time, const char* name);
Event(const Event & event);
~Event();
Event & operator = (Event & right);
void set();
void setName(const char* name);
const char* getName() const;
void setTime(const Time & time);
Time getTime() const;
bool isValid() const;
long getSeconds() const;
void print() const;
static int eventsGenerated();
private:
Time time;
char* name;
static int count;
};
#endif
//Time class
class Time
{
public:
// default constructor
Time();
Time(int hr, int min, int sec = 0);
// copy constructor
Time(const Time & time);
// assignment operator
Time & operator=(Time & time);
// destructor
~Time();
void print() const;
bool set();
bool isValid() const;
bool istime(int hour, int minute, int second) const;
void setHour(int hour);
int getHour() const;
void setMinute(int minute);
int getMinute() const;
void setSecond(int second);
int getSecond() const;
private:
inline bool isleap(int year) const; // utility function
int hour, minute, second;
};
#endif
The event default constructor sets time to default values and name to an empty string. I have to use class composition.
I dont have a problem with seeting name to an empty string, i'm having problems setting time to default values. I know how to do it using inheritance, but not with class composition.
This is what i have done, but i keep on getting compile errors
//testdriver.cpp
Event::Event() : Time(hour, minute, second)
{
for (int i =0; i < 100; i++)
{
name[i] = NULL;
}
}
any suggestions?