Hi
I have been trying to compile this code, in this I had a class clocktype with its header and implementation file and now I have to extend this class to be able to implement the function timezone in it. This is a program where I have to use two header files in my derived class.
I am posting my code here:
And now I have the derived classCode://header file clocktype #ifndef h_clocktype #define h_clocktype #include<string> using namespace std; class clocktype { public: void settime(int hours, int minutes, int seconds); void gettime(int& hours, int& minutes, int& seconds); void printtime(); void incseconds(); void incminutes(); void inchours(); clocktype (int hours, int minutes, int seconds); clocktype(); protected: int hr; int min; int sec; }; #endif // implemnetation file #include<iostream> #include<conio.h> #include "clocktype.h" using namespace std; 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) { hours=hr; minutes=min; seconds=sec; } void clocktype::printtime() { if(hr<10) cout<<"0"; cout<<hr<<":"; if(min<10) cout<<"0"; cout<<min<<":"; if(sec<10) cout<<"0"; cout<<sec; } void clocktype::inchours() { hr++; if(hr<23) hr=0; } void clocktype::incminutes() { min++; if(min<59) min=0; inchours(); } void clocktype::incseconds() { sec++; if(sec<59) sec=0; incminutes(); } clocktype::clocktype() { hr=0; min=0; sec=0; } clocktype::clocktype(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; } // main function int main() { clocktype myclock; myclock.settime( 12, 14, 40); cout<<" The time now is : "; myclock.printtime(); myclock.settime( 24, 60, 60); cout<<"\n The time now is : "; myclock.printtime(); getch(); }
Code:#ifndef h_clocktype2 #define h_clocktype2 #include<iostream> #include"clocktype.h" using namespace std; enum zonetype {GMT, EST, PST, IST, CET}; class clocktype2: public clocktype { public: void settime(int hours, int minutes, int seconds,zonetype timezone); void printtime(); clocktype2 (int hours, int minutes, int seconds, zonetype timezone); clocktype2(); private: zonetype tz; }; #endif #include<iostream> #include<conio.h> #include"clocktype.h" #include"clocktype2.h" using namespace std; void clocktype2::settime(int hours, int minutes, int seconds, zonetype timezone) { hours=hr; minutes=min; seconds=sec; timezone=tz; } void clocktype2::printtime() { switch(tz) { case GMT: cout<<"GMT"; break; case EST: cout<<"EST"; break; case PST: cout<<"PST"; break; case IST: cout<<"IST"; break; case CET: cout<<"CET"; break; } } clocktype2::clocktype2(){ hr=0; min=0; sec=0; tz=GMT; } clocktype2::clocktype2(int hours, int minutes, int seconds, zonetype timezone) { hours=hr; minutes=min; seconds=sec; timezone=tz; } int main() { clocktype2 clock; clock.settime( 12, 14, 40, GMT); cout<<" The time now is : "; clock.printtime(); clock.settime( 24, 60, 60, IST); cout<<"\n The time now is : "; clock.printtime(); getch(); }
Now when I try to run this program it gives me the following error:
------ Build started: Project: lab-4, Configuration: Debug Win32 ------
Linking...
clocktypeimp2.obj : error LNK2019: unresolved external symbol "public: __thiscall clocktype::clocktype(void)" (??0clocktype@@QAE@XZ) referenced in function "public: __thiscall clocktype2::clocktype2(void)" (??0clocktype2@@QAE@XZ)
C:\Documents and Settings\user\My Documents\Visual Studio 2008\Projects\lab-4\Debug\lab-4.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\user\My Documents\Visual Studio 2008\Projects\lab-4\lab-4\Debug\BuildLog.htm"
lab-4 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



LinkBack URL
About LinkBacks



