如何修复错误 2298 和 2563
How do I fix errors 2298 and 2563
我正在尝试为作业制作一个类。它应该记录程序运行需要多长时间以及循环循环的次数,然后将该信息放入文件中。现在,它给了我:
error 2298 "missing call to bound pointer to member function"
和
error 2563 "mismatch in formal parameter list."
我很难弄清楚如何解决这些问题; 它可能没有我做的那么复杂,但任何帮助将不胜感激。
#include <thread>
#include <iostream>
#include <fstream>
#include <chrono>
#include <string>
using namespace std;
class Timer {
private:
typedef chrono::high_resolution_clock Clock;
Clock::time_point epoch;
public:
Timer() {
epoch = Clock::now();
}
Clock::duration getElapsedTime() { return Clock::now() - epoch; }
};
int loopCount()
{
for (int count=0;count<=100;) {
count++;
}
return count;
}
int fProjectDebugFile()
{
fstream debugFile;
debugFile.open ("FinalProjectDebugger.txt", fstream::out | fstream::app);
string jar(Timer);
cout << jar << endl << loopCount() << endl;
debugFile.close();
return 0;
}
不能在循环外部访问循环变量。
因此,将声明移到循环之外,即替换以下内容:
int loopCount(){
for(int count=0;count<=100;){
count++;}
return count;
}
有了这个:
int loopCount()
{
int count = 0;
while (count <= 100)
{
count++;
}
return count;
}
另外,这个:
class Timer
...
string jar(Timer);
没有多大意义。Timer
是一种类型,因此string jar(Timer);
声明一个名为jar
的函数,该函数将Timer
对象作为参数并返回string
。
相关文章: