| flyer86 (4) | |
|
HI FRIENDS I AM USING MICROSOFT VISUAL C++ 2010 EXPRESS. PLEASE, HELP REQUIRED REGARDING COMPILING ERROR. THANKS FOLLOWING IS THE ERROR WHILE COMPILING 1>------ Build started: Project: my first program, Configuration: Debug Win32 ------ 1>my first program.obj : error LNK2005: _main already defined in Ajust time class.obj 1>C:\Documents and Settings\Talha\My Documents\Visual Studio 2010\Projects\my first program\Debug\my first program.exe : fatal error LNK1169: one or more multiply defined symbols found ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ======== THIS IS THE CODE: #include <iostream> #include <conio.h> using namespace std; class Time { private: int days,hours,minutes,seconds; void adjust_time(); public: Time(int d, int h, int m, int s); Time(int s); Time () {} ~Time() {} int total_seconds(); void output(); Time operator + (Time a); }; Time::Time (int d, int h, int m, int s) { days= d; hours= h; minutes =m; seconds =s; adjust_time(); } void Time :: adjust_time() { while (seconds>=60) { seconds-=60; minutes++; } while (minutes>=60) { minutes-=60; hours++; } while (hours>=24) { hours-=24; days++; } } Time :: Time (int s) { seconds= s; minutes=hours=days= 0; adjust_time(); } int Time :: total_seconds() { return(seconds+(minutes*60)+(hours*60*60)+(days*24*60*60) ); } Time Time :: operator + (Time a) { return(total_seconds() + a.total_seconds() ); } void Time :: output() { cout << days << " days " << hours << " hours " << minutes << " minutes " << seconds << " seconds "; } int main () { Time t1(0); t1 = t1 + Time (0,23,50,35); cout << "Time Addition" << endl; t1.output(); return 0; } | |
|
|
|
| Zhuge (2871) | |
|
It looks like you're linking two files that each have a main() defined... Are there any other files involved here? Also, this probably doesn't belong in the Lounge. | |
|
|
|