Member Avatar for pagantom

I'm lost. why won't my objects instantate?

Here's the code, compiler errors are below. thanks

class date
{
      private:
              char *mo;
              int day, yr;
              
      public:
              date()
                    {*mo = 0;
                    day = 0;
                    yr = 0;}
              
              date (char *m, int d, int y)
                   {mo = new char[strlen(m)+1];
                   strcpy(mo, m);
                   day = d;
                   yr = y;}
              
              date(const date &obj)
                   {mo = new char[strlen(obj.mo)+1];
                   strcpy(mo, obj.mo);
                   day = obj.day;
                   yr = obj.yr;}
              
              ~date()
                     {delete[] mo;}
              
              const char *getMo()
                    {return mo;}
                    
              int getDay()
                  {return day;}
              int getYr()
                  {return yr;}
                  
              void operator=(const date &right)
                  { delete [] mo;
                  mo = new char[strlen(right.mo) + 1];
                  strcpy(mo, right.mo);
                  day = right.day;
                  yr = right.yr;}
};                  
                 
class time:public date
{
      private:
              int hr, min, sec;
                  
      public:
                             
              time (int hh, int mm, int ss)
                   {hr = hh;
                   min = mm;
                   sec = ss;}
              
              time(const time &obj)
                   {hr = obj.hr;
                   min = obj.min;
                   sec = obj.sec;}              
                                  
              int getHour()
                  {return hr;}
              int getMin()
                  {return min;}
              int getSec()
                  {return sec;}
};
int main()
{
   time first("January", 1, 2007);
   
   time second("January", 2, 2007);
   
   time reverse = first;
   cout << "first date = " << first.getMo();
   cout << "/" << first.getDay();
   cout << "/" << first.getYr() << endl;
   cout << "second date = " << second.getMo();
   cout << "/" << second.getDay();
   cout << "/" << second.getYr() << endl;
   reverse = second;
   second = first; 
   
   cout << "now first date =  " << reverse.getMo();
   cout << "/" << reverse.getDay();
   cout << "/" << reverse.getYr() << endl;
   
   cout << "now second date =  " << second.getMo();
   cout << "/" << second.getDay();
   cout << "/" << second.getYr() << endl;

Compiler errors:

In function `int main()':
expected `;' before "first"
warning: statement is a reference, not call, to function `time'
expected `;' before "second"
warning: statement is a reference, not call, to function `time'
expected `;' before "reverse"
warning: statement is a reference, not call, to function `time'

That is because time( ) is a function in standard C++ found in the ctime header file.

You can't name program variables with the names of standard functions. If you will observe closely, that is also what those errors say out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.