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()
}
내가 디버깅 할 때, 그것은
컴파일러를 말한다 "C를 : 데브 - CPP \ Makefile.win \" 만들 실행 ... 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/mingw32"-I "C :/Dev-Cpp// 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
당신을 감사합니다, 그것은 일을 다음 코드를 참조하십시오 – DNilla