hi;
I have this code in my book and when I copied it into my compiler into two files, one is header and the other is .cpp. it gives me an error, I'm sure I copied it right but can't figure out the error.
here is my code:
Time.h
// declaration of class time.
// membar functions defined in Time.cpp
// prevent multiple inclusions of header file
#ifndef TIME_H
#define TIME_H
// Time abstract data type definition
class Time
{
public:
Time( int=0, int=0, int=0 ); //default constructor
// set functions
void setTime ( int,int,int); // set hour, minute, second
void setHour ( int ); // set hour ( after validation )
void setMinute ( int ); // set minute ( after validation )
void setSecond ( int ); // set second ( after validation )
// get functions
int getHour(); // return hour
int getMinute(); // return minute
int getSecond(); // return second
void printUniversal( );// print time in universal time format
private:
int hour; // 0-23 ( 24 hour clock format )
int minute; // 0-59
int second; // 0-59
}; // end class Time
#endif
------------------------------------------------------------------------------------------------
Time.cpp
#include <iostream>
using std::cout;
#include <iomanip>
using std::setfill;
using std::setw;
#include "Time.h" // include definition from class Time from Time.h
Time::Time( int hr, int min, int sec )
{
setTime( hr, min, sec );
}
void Time::setTime( int h, int m , int s )
{
setHour (h);
setMinute (m);
setSecond (s);
}
void Time::setHour ( int h )
{
hour = ( h >= 0 && h < 24 ) ? h : 0;
}
void Time::setMinute ( int m )
{
minute = ( m >= 0 && m < 60 ) ? m : 0;
}
void Time::setSecond ( int s )
{
second = ( s >= 0 && s < 60 ) ? s : 0;
}
int Time::getHour()
{
return hour;
}
int Time::getMinute ()
{
return minute;
}
int Time::getSecond ()
{
return second;
}
void Time::printUniv ersal()
{
cout<< setfill( '0' ) << setw(2)<<getHou r()<<":"<<setw( 2)<<getMinute() <<":"<<setw(2)< <getSecond();
}
---------------------------------------------------------------------------------------------------------------
the error message:
------ Build started: Project: example2, Configuration: Debug Win32 ------
Linking...
LIBCMT.lib(crt0 .obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStar tup
C:\Documents and Settings\Owner\ My Documents\Visua l Studio 2005\Projects\e xample2\Debug\e xample2.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Owner\ My Documents\Visua l Studio 2005\Projects\e xample2\example 2\Debug\BuildLo g.htm"
example2 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
--------------------------------------------------------------------------------------------------
your fast responce is highly appreciated. thanks in advance for your cooperation.
ayman723
I have this code in my book and when I copied it into my compiler into two files, one is header and the other is .cpp. it gives me an error, I'm sure I copied it right but can't figure out the error.
here is my code:
Time.h
// declaration of class time.
// membar functions defined in Time.cpp
// prevent multiple inclusions of header file
#ifndef TIME_H
#define TIME_H
// Time abstract data type definition
class Time
{
public:
Time( int=0, int=0, int=0 ); //default constructor
// set functions
void setTime ( int,int,int); // set hour, minute, second
void setHour ( int ); // set hour ( after validation )
void setMinute ( int ); // set minute ( after validation )
void setSecond ( int ); // set second ( after validation )
// get functions
int getHour(); // return hour
int getMinute(); // return minute
int getSecond(); // return second
void printUniversal( );// print time in universal time format
private:
int hour; // 0-23 ( 24 hour clock format )
int minute; // 0-59
int second; // 0-59
}; // end class Time
#endif
------------------------------------------------------------------------------------------------
Time.cpp
#include <iostream>
using std::cout;
#include <iomanip>
using std::setfill;
using std::setw;
#include "Time.h" // include definition from class Time from Time.h
Time::Time( int hr, int min, int sec )
{
setTime( hr, min, sec );
}
void Time::setTime( int h, int m , int s )
{
setHour (h);
setMinute (m);
setSecond (s);
}
void Time::setHour ( int h )
{
hour = ( h >= 0 && h < 24 ) ? h : 0;
}
void Time::setMinute ( int m )
{
minute = ( m >= 0 && m < 60 ) ? m : 0;
}
void Time::setSecond ( int s )
{
second = ( s >= 0 && s < 60 ) ? s : 0;
}
int Time::getHour()
{
return hour;
}
int Time::getMinute ()
{
return minute;
}
int Time::getSecond ()
{
return second;
}
void Time::printUniv ersal()
{
cout<< setfill( '0' ) << setw(2)<<getHou r()<<":"<<setw( 2)<<getMinute() <<":"<<setw(2)< <getSecond();
}
---------------------------------------------------------------------------------------------------------------
the error message:
------ Build started: Project: example2, Configuration: Debug Win32 ------
Linking...
LIBCMT.lib(crt0 .obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStar tup
C:\Documents and Settings\Owner\ My Documents\Visua l Studio 2005\Projects\e xample2\Debug\e xample2.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Owner\ My Documents\Visua l Studio 2005\Projects\e xample2\example 2\Debug\BuildLo g.htm"
example2 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
--------------------------------------------------------------------------------------------------
your fast responce is highly appreciated. thanks in advance for your cooperation.
ayman723
Comment