请大家帮帮忙啊!!!好难!!
各位大侠们:小生今天遇到这样的问题.
我编程用了3个文件一是头文件.两个cpp文件,但是我的编译没有问题但是组建时发现一个错误,错误如下:
--------------------Configuration: time - Win32 Debug--------------------
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/time.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.
time.exe - 1 error(s), 0 warning(s)
我新建一个是win32 application 空文件
第一个头文件是:
//time.h#ifndef TIME4_H
#define TIME4_H
class Time {
public:
Time(int =0,int =0,int =0);
void setTime(int,int,int);
int getHour();
int &badSetHour(int);
private:
int hour;
int minute;
int second;
};
#endif
第二个:
time4.cpp
#include<iostream.h>
#include"time4.h"
Time::Time(int hr,int min,int sec)
{
setTime(hr,min,sec);
}
void Time::setTime(int h,int m,int s)
{
hour=(h>=0&&h<24)?h:0;
minute=(m>=0&&m<60)?m:0;
second=(s>=0&&s<60)?s:0;
}
int Time::getHour(){return hour;}
int &Time::badSetHour(int hh)
{
hour=(hh>=0&&hh<24)?hh:0;
return hour;
}
第三个是:
//time.cpp#include<iostream.h>
#include"time4.h"
int main()
{
Time t;
int &hourRef=t.badSetHour(20);
cout<<"Hour befoe modification:"<<hourRef;
hourRef=30;
cout<<"\nhour after modification:"<<t.getHour();
t.badSetHour(12)=74;
cout<<"\n\n************************\n"
<<"POOR PROGRAMMING PRACTICE!!!!\n"
<<"badsetHour as an lvalue,Hour:"
<<t.getHour()
<<"\n***************************"<<endl;
return 0;
}