如何修复错误2298和2563

问题描述 投票:-1回答:1

我正在尝试为作业分配课程。应该记录一个程序运行需要多长时间,一个循环要循环多少次,然后将该信息放入文件中。现在,它给了我:

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;
}
c++
1个回答
1
投票

您无法在循环外部访问循环变量。

因此,将声明移到循环外,即替换为:

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

© www.soinside.com 2019 - 2024. All rights reserved.