我要编写一个测试程序,测试上一个问题中设计的类上的各种操作;显示clockType
重载作为成员函数的定义。使用 Dev C++ 编译器编译时出现以下错误。
错误内容如下:
[link error] undefined reference "WinMain@16'
Id returned 1 exit status
这是我的代码:
#include <iostream>
using namespace std;
class clockType
{
public:
void setTime (int hours, int minutes, int seconds);
void getTime (int& hours, int& minutes, int& seconds) const;
clockType operator++();
bool operator==(const clockType& otherClock) const;
bool operator!= (const clockType& otherClock) const;
bool operator<=(const clockType& otherClock) const;
bool operator<(const clockType& otherClock) const;
bool operator>=(const clockType& otherClock) const;
bool operator>(const clockType& otherClock) const;
clockType ();
clockType (int hours = 0, int minutes = 0, int seconds = 0);
private:
int hr;
int min;
int sec;
};
clockType clockType::operator++()
{
sec++;
if (sec > 59)
{
sec = 0;
min++;
if (min > 59)
{
min = 0;
hr++;
if (hr > 23)
hr = 0;
}
}
return *this;
}
bool clockType::operator==(const clockType& otherClock) const
{
return (hr == otherClock.hr && min == otherClock.min && sec == otherClock.sec);
}
bool clockType::operator<=(const clockType& otherClock) const
{
return ((hr < otherClock.hr) || (hr == otherClock.hr && min < otherClock.min) || (hr == otherClock.hr && min == otherClock.min && sec <= otherClock.sec));
}
bool clockType::operator!=(const clockType& otherClock) const
{
return (hr != otherClock.hr || min != otherClock.min || sec != otherClock.sec);
}
bool clockType::operator<(const clockType& otherClock) const
{
return ((hr < otherClock.hr) || (hr == otherClock.hr && min < otherClock.min) || (hr == otherClock.hr && min == otherClock.min && sec < otherClock.sec));
}
bool clockType::operator>=(const clockType& otherClock) const
{
return ((hr > otherClock.hr) || (hr == otherClock.hr && min > otherClock.min) || (hr == otherClock.hr && min == otherClock.min && sec >= otherClock.sec));
}
bool clockType::operator>(const clockType& otherClock) const
{
return ((hr > otherClock.hr) || (hr == otherClock.hr && min > otherClock.min) || (hr == otherClock.hr && min == otherClock.min && sec > otherClock.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;
}
clockType::clockType(int hours, int minutes, int seconds)
{
setTime(hours, minutes, seconds);
}
对此问题的任何帮助将不胜感激。我并不擅长编程,我只是不知道为什么会出现这种错误。到目前为止,我还没有为课堂编写的其他程序。