c++ - How to call a function from a separate cpp file in the main.cpp file? -
i have following timer.cpp, timer.h, , main.cpp files. trying call functions timer.cpp file in main.cpp file , have included timer.h in main, still not working. can please explain why? little rusty c++ , feel making silly mistake. in advance help.
#timer.h file #ifndef __notes__timer__ #define __notes__timer__ #include <iostream> class timer { public: timer(); void start(); void stop(); void clear(); float getdelta(); }; #endif
#timer.cpp file #include "timer.h" clock_t starttime; clock_t stoptime; timer::timer(){ starttime = 0; stoptime = 0; }//timer void start(){ starttime = clock(); }//start void stop(){ stoptime = clock(); }//stop float getdelta(){ return stoptime-starttime; }//getdelta
#main.cpp file #include "timer.h" #include <iostream> using namespace std; int main(){ char quit; start(); cout << "would quit? y or n: "; cin >> quit; if (quit != 'y' || quit != 'y'){ while (quit != 'y' || quit != 'y'){ cout << "would quit? y or n: "; cin >> quit; }//while }//if else { stop(); cout << getdelta(); exit(0); }//else }//main
you can use these functions in timer.c , use class::function
Comments
Post a Comment