类计时器中的重载前缀和后缀增量。调试时出现问题

迪尼拉

我需要为类Timer重载增量。我班的成员只有几分钟和几秒钟。

#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()
  }

当我调试时,它说

编译器:默认编译器构建Makefile:“ C:\ Dev-Cpp \ Makefile.win”正在执行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' with no type

main.cpp:18: error: ISO C++ forbids declaration of `Time' with no type
main.cpp:29: error: ISO C++ forbids declaration of `Time' with 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' with 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 this function)

main.cpp:26: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp: At global scope:
main.cpp:56: error: new types may not be defined in a 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 this function)
main.cpp:57: error: expected `;' before "T1"
main.cpp:59: error: `T1' undeclared (first use this function)
main.cpp:64: error: `T2' undeclared (first use this function)
main.cpp:69: error: expected `;' before '}' token

make.exe: *** [main.o] Error 1

Execution terminated
湿婆

对象应该是计时器类型而不是时间类型。尝试匹配类名和构造函数名。

在displayTime方法中未定义小时成员。

void displayTime()
  {
     cout << "M: " << minutes << " S:" << seconds <<endl;
  }

请参考以下代码http://ideone.com/m50w2r

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

javascript计时器和php变量出现问题

来自分类Dev

前缀和后缀增量

来自分类Dev

在 Kivy 中实现计时器时遇到问题

来自分类Dev

stl迭代器的后缀和前缀增量之间的区别?

来自分类Dev

C中的前缀和后缀增量之间的差异(++ a和a ++)

来自分类Dev

在服务和活动中启动计时器时的区别

来自分类Dev

使用jQuery和PHP添加类时出现问题

来自分类Dev

使用类和索引单击元素时出现问题

来自分类Dev

C#中的前缀和后缀运算符重载

来自分类Dev

C#中的前缀和后缀运算符重载

来自分类Dev

尝试在Android中创建倒数计时器时出现运行时异常和空指针异常

来自分类Dev

在JS中清除计时器的问题

来自分类Dev

在JS中清除计时器的问题

来自分类Dev

在ReactJs中制作计时器/倒计时代码时遇到问题

来自分类Dev

可以从类中调用的计时器

来自分类Dev

如何在Android中启动增量计时器

来自分类Dev

R中的前缀后缀和前缀后缀

来自分类Dev

在 AngularJS 中创建控制器时出现问题

来自分类Dev

for循环中的前缀和后缀增量

来自分类Dev

在dompdf和cakephp中显示rowspan时出现问题

来自分类Dev

尝试安排计时器时出现 IllegalStateException

来自分类Dev

在C ++中实现计时器/股票代码类时需要帮助

来自分类Dev

ASP.NET线程计时器中的用户和权限问题

来自分类Dev

使用 Systemd 计时器时 tar 的问题

来自分类Dev

倒数计时器问题

来自分类Dev

Android:计时器问题

来自分类Dev

摇摆计时器问题

来自分类Dev

JavaScript 计时器的问题

来自分类Dev

SIGALRM,间隔计时器和sleep()问题