c++ - Overloading prefix and postfix increment in class timer. Problems while debugging -


i need overload increment class timer. members of class minutes , seconds.

#include <iostream> #include <conio.h> using namespace std;  class timer { private:   int minutes;              int seconds;              public:    time(){      minutes = 0;      seconds = 0;    }   time(int m, int s){      minutes = m;      seconds = s;    }    void displaytime()   {      cout << "m: " << hours << " s:" << minutes <<endl;   }    time operator++ ()     {      ++seconds;                if(seconds >= 60)        {         ++minutes;         seconds -= 60;      }      return time(minutes, seconds);   }    time operator++( int )            {       time t(minutes, seconds);       ++seconds;                          if(seconds >= 60)      {         ++minutes;         seconds -= 60;      }       return t;    }   };   int main()   {   time t1(18, 23), t2(19,12);    ++t1;                       t1.displaytime();          ++t1;                      t1.displaytime();          t2++;                     t2.displaytime();         t2++;                      t2.displaytime();          _getch()   } 

when debug, says

compiler: default compiler building makefile: "c:\dev-cpp\makefile.win" executing make... make.exe -f "c:\dev-cpp\makefile.win" g++.exe -c main.cpp -o main.o -i"c:/dev-cpp/lib/gcc/mingw32/3.4.2/include" -i"c:/dev-cpp/include/c++/3.4.2/backward" -i"c:/dev-cpp/include/c++/3.4.2/mingw32" -i"c:/dev-cpp/include/c++/3.4.2" -i"c:/dev-cpp/include"

main.cpp:13: error: iso c++ forbids declaration of `time' no type  main.cpp:18: error: iso c++ forbids declaration of `time' no type main.cpp:29: error: iso c++ forbids declaration of `time' no type  main.cpp:29: error: expected `;' before "operator" main.cpp:40: error: expected `;' before "time" main.cpp:40: error: iso c++ forbids declaration of `time' no type main.cpp:40: error: expected `;' before "operator"  main.cpp:54: error: expected `;' before '}' token main.cpp: in member function `void timer::displaytime()': main.cpp:26: error: `hours' undeclared (first use function)  main.cpp:26: error: (each undeclared identifier reported once each function appears in.) main.cpp: @ global scope: main.cpp:56: error: new types may not defined in return type main.cpp:56: error: extraneous `int' ignored main.cpp:56: error: `main' must return `int' main.cpp: in function `int main(...)': main.cpp:57: error: `time' undeclared (first use function) main.cpp:57: error: expected `;' before "t1" main.cpp:59: error: `t1' undeclared (first use function) main.cpp:64: error: `t2' undeclared (first use function) main.cpp:69: error: expected `;' before '}' token  make.exe: *** [main.o] error 1  execution terminated 

object should of type timer not time. try match class name , constructor name.

hour member not defined in displaytime method.

void displaytime()   {      cout << "m: " << minutes << " s:" << seconds <<endl;   } 

please refer following code http://ideone.com/m50w2r


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -