我有以下 Timer.cpp、Timer.h 和 main.cpp 文件。我正在尝试从我的 main.cpp 文件中的 Timer.cpp 文件中调用函数,并将 Timer.h 包含在 main.cpp 中,但它仍然无法正常工作。有人可以解释为什么吗?我对 C++ 有点生疏,感觉自己犯了一个愚蠢的错误。提前感谢您的帮助。
#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 you like to quit? Y or N: ";
cin >> quit;
if (quit != 'Y' || quit != 'y'){
while (quit != 'Y' || quit != 'y'){
cout << "Would you like to quit? Y or N: ";
cin >> quit;
}//while
}//if
else {
stop();
cout << getDelta();
exit(0);
}//else
}//main