I am having a hard time linking my header file with my cpp file.
My header file time24.h is as follows:
time24(int h = 0, int m = 0);
// Constructor initializes hour and minute
void addTime(int m);
//update time by adding m minutes to the current time
//Precondition: m must be >=0
time24 duration(const time24& t);
// return the length of time from some current time to some later time
// time t as a time24 value
// Reads in time from keyboard in hh:mm format
//Postcondition: Assign value hh to hour and mm to minute
// normalize time
void writeTime() const;
//display the time on screen in HH:MM format
//ACCESS MEMBER FUNCTIONS
// return the hour value for the current time
//return the minute value for the current time
int hour,minute; //data members
// Utility function that sets the hours value in the range 0 -23
// and the minute value in the range 0 - 59
And then my class implementations are in my time24.cpp file
which is as follows:
using namespace std;
//FUNCTION normalizeTime(): Sets hours and minutes within their proper ranges
int extraHours = minute/60;
//set minutes in range from 0 to 59
//Update hour. Set in range 0-23
hour = (hour + extraHours) % 24;
// CONSTRUCTOR: creates time 24 object with initial arguments h and m
time24::time24(int h , int m):hour(h),minute(m)
//put hour and minute in the correct range
//FUNCTION duration(): returns time24 object with difference in time in
time24 time24::duration(const time24& t)
//convert currTime and time t to minutes
int currTime = (hour * 60)+minute;
int tTime = (t.hour*60)+t.minute;
// return anonymous object
//FUNCTION readTime(): reads in time from keyboard
//make sure hour and minute are in range
//FUNCTION getHour():Accesses private data member hour
//FUNCTION getMinute(): Accesses private data member minute
//FUNCTION writeTime(): displays time24 object in HH:MM format on screen
//Function addTime(int m): adds m number of minutes to a time24 object
void time24::addTime(int m)
minute += m;
Ive reviewed my work several times and cant figure out while my files wont link ....
I recieve the following errors
Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup MSVCRTD.lib DYLAN
Error 2 fatal error LNK1120: 1 unresolved externals C:\Documents and Settings\dh63265\My Documents\Visual Studio 2008\Projects\DYLAN\Debug\DYLAN.exe DYLAN
Ive tried googling these errors and tried the necessary fixes I could find but messing with linker advanced properties which was usually the recommended fix did not work.
The reason for the error is quite simple: That's no complete C++ program because it doesn't contain a main() function.
As-is, it's solely a class definition, of which you only can produce an .obj file (that is the output of the compiler, no need to link) or at best a .lib file. Either of these could then be linked to a compete program that uses the class.
So you have to either 1) add a main() function or 2) change your project settings to produce either an .obj or a .lib file. You didn't say in your post which development package you use. Posting in the Visual C++ forum suggests that it is likely to be VC++. But which version? Knowing that, probably someone can tell you which settings to change.
Please use code tags the next time you post code. It will make your code much more readable and help people who are going to help you.
Awesome... I understand that sooo I just need to compile the file without linking?? Unless of course I include a source file with an executable main() function. I currently use linux EMACS system for my computer science course and creating .obj files in emacs is very easy. However, outside the course I use microsoft visual studious 2008 and I have NO idea how to create obj files using the program. Could anyone help me solve this problem? Thanks in advance
Awesome... I understand that sooo I just need to compile the file without linking?? Unless of course I include a source file with an executable main() function. I currently use linux EMACS system for my computer science course and creating .obj files in emacs is very easy. However, outside the course I use microsoft visual studious 2008 and I have NO idea how to create obj files using the program. Could anyone help me solve this problem? Thanks Eri523.. Thanks to all in advance.