Thread: Problem with class/derived class

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    85

    Question Problem with class/derived class

    Ok...i dont know how this is giving me an error- i have checked with so many sources including my notes from class and it matches with what I have but the compiler is giving me this error:
    Code:
    135: error: expected unqualified-id before â{â token
    135: error: expected `)' before â{â token
    here is my WHOLE program....the teacher gave us the whole base class- and we had to do the derived class from it. I have not put the print function in yet but i will after i can get this to work!!! Please someone help!!!!!!

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    class clockType
    {
    public:
      void setTime(int hours, int minutes, int seconds);
      void getTime(int& hours, int& minutes, int& seconds) const;
      void printTime() const;
      void incrementSeconds();
      void incrementMinutes();
      void incrementHours();
      bool equalTime(const clockType& otherClock) const;
      clockType(int hours, int minutes, int seconds);
      clockType();
    
    private:
      int hr, min, sec;
    };
    
    void clockType::setTime(int hours, int minutes, int seconds)
    {
      if (0 <= hours && hours < 24)
        hr = hours;
      else
        hr = 0;
      if (0 <= minutes && minutes < 60)
        min = minutes;
      else
        min = 0;
      if (0 <= seconds && seconds < 60)
        sec = seconds;
      else
        sec = 0;
    }
    
    void clockType::getTime(int& hours, int& minutes, int& seconds) const
    {
      hours = hr;
      minutes = min;
      seconds = sec;
    }
    
    void clockType::incrementHours()
    {
      hr++;
      if (hr > 23)
        hr = 0;
    }
    
    void clockType::incrementMinutes()
    {
      min++;
      if (min > 59)
       {
         min = 0;
         incrementHours();
       }
    }
    
    void clockType::incrementSeconds()
    {
     sec++;
     if (sec > 59)
      {
       sec = 0;
       incrementMinutes();
      }
    }
    
    void clockType::printTime() const
    {
     if (hr < 10)
       cout << "0" << hr << ":";
     if (min < 10)
       cout << "0" << min << ":";
     if (sec < 10)
       cout << "0" << sec;
    }
    
    bool clockType::equalTime(const clockType& otherClock) const
    {
      return (hr == otherClock.hr && min == otherClock.min && sec == otherClock.sec);
    }
    
    clockType::clockType(int hours, int minutes, int seconds)
    {
      if (0 <= hours && hours < 24)
        hr = hours;
      else
        hr = 0;
      if (0 <= minutes && minutes < 60)
        min = minutes;
      else
        min = 0;
      if (0 <= seconds && seconds < 60)
        sec = seconds;
      else
        sec = 0;
    }
    
    clockType::clockType()
    {
     hr = 0;
     min = 0;
     sec = 0;
    }
    
    class extclockType:public clockType
    {
    public:
     extclockType();
     extclockType(int hours, int minutes, int seconds, string timezone);
     void print() const;
     void setTime(int hours, int minutes, int seconds, string timezone);
      //string getTimeZone();
    
    private:
     string tz;
    };
    
    extclockType::extclockType()
    {
     tz = " ";
    }
    
    extclockType(int hours, int minutes, int seconds, string timezone):clockType(hours,minutes,seconds)            //this is where the error is coming in
    {
     tz = timezone;
    }
    
    void extclockType::setTime(int hours, int minutes, int seconds, string timezone)
    {
     tz = timezone;
    }
    
    
    int main()
    {
     int h1, m1, s1, h2, m2, s2;
     string zn1, zn2;
    
     cin >> h1 >> m1 >> s1 >> zn1;
    
     cin >> h2 >> m2 >> s2 >> zn2;
    
     extclockType time1(h1, m1, s1, zn1);
    
     extclockType time2;
    
     cout << "Time 1: ";
     time1.printTime();
     cout << endl;
    
     time2.setTime(h2, m2, s2, zn2);
    
     cout << "Time 2: ";
     time2.printTime();
     cout << endl;
    
     time2.incrementSeconds();
    
     cout << "After incrementing time2 by one second, Time 2: ";
     time2.printTime();
     cout << endl;
    
     return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2005
    Posts
    271
    You forgot the class scope identifier on your second constructor.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    85
    thanks so much- must have overlooked it (a thousand times). Thanks again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  3. Problem with friend class declaration in a namespace
    By Angus in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2008, 01:29 PM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM