这些错误消息告诉我什么? 我正在努力学习C++,所以我为这个愚蠢的问题道歉,如果我得到了这个基本的东西,我会明白很多。我遵循一个指南,创建一个键盘记录器,意在教C++做这件事。但是解释太弱,在完全按照指示编写程序并尝试调试后,我得到: |===构建:测试中调试(编译器:GNU GCC编译器)===| :\example\test\test\Timer.h | 14 |错误:“nullpointr”未在此范围内声明| :\example\test\test\Timer.h |在构造函数“Timer::Timer(const std::function&,const long unsigned int&,long int)”中:| :\example\test\test\Timer.h | 44 |错误:调用“(std::chrono::millides{aka std::chrono::duration})(std::chrono::millides)”时不匹配| :\example\test\test\Timer.h | 45 |错误:表达式不能用作函数| |==生成失败:3个错误,0个警告(0分钟,0秒))===|
我很抱歉我的第一个问题没有被很好地构造,但我不知道从哪里开始,因为我完全缺乏经验。我不知道错误消息应该告诉我什么,以及如何理解引用等。因此,如果有人能够解释这几条消息的不同含义,例如“nullpointr”没有在此范围内声明,我将非常感激"... 我试图在“已问已答”中找到答案,但我不知道如何找到获得答案所需的解释。我想您只需要查看这个头的代码,因为其他头是无错误的。。。?这是(很抱歉代码太难看了,我复制的代码缩进了“{”和“}”,但粘贴时,大部分代码都显示在左边:这些错误消息告诉我什么? 我正在努力学习C++,所以我为这个愚蠢的问题道歉,如果我得到了这个基本的东西,我会明白很多。我遵循一个指南,创建一个键盘记录器,意在教C++做这件事。但是解释太弱,在完全按照指示编写程序并尝试调试后,我得到: |===构建:测试中调试(编译器:GNU GCC编译器)===| :\example\test\test\Timer.h | 14 |错误:“nullpointr”未在此范围内声明| :\example\test\test\Timer.h |在构造函数“Timer::Timer(const std::function&,const long unsigned int&,long int)”中:| :\example\test\test\Timer.h | 44 |错误:调用“(std::chrono::millides{aka std::chrono::duration})(std::chrono::millides)”时不匹配| :\example\test\test\Timer.h | 45 |错误:表达式不能用作函数| |==生成失败:3个错误,0个警告(0分钟,0秒))===|,c++,C++,我很抱歉我的第一个问题没有被很好地构造,但我不知道从哪里开始,因为我完全缺乏经验。我不知道错误消息应该告诉我什么,以及如何理解引用等。因此,如果有人能够解释这几条消息的不同含义,例如“nullpointr”没有在此范围内声明,我将非常感激"... 我试图在“已问已答”中找到答案,但我不知道如何找到获得答案所需的解释。我想您只需要查看这个头的代码,因为其他头是无错误的。。。?这是(很抱歉代码太难看了,我复制的代码缩进了“{”和“}”,但粘贴时,大部分代码都显示在左边: #ifndef TIMER_
#ifndef TIMER_H
#define TIMER_H
#include <thread>
#include <chrono>
class Timer
{
std::thread Thread;
bool Alive = false;
long CallNumber = -1L;
long repeat_count = -1L;
std::chrono::milliseconds interval = std::chrono::milliseconds(0);
std::function<void(void)> funct = nullpointr;
void SleepAndRun()
{
std::this_thread::sleep_for(interval);
if(Alive)
Function()();
}
void ThreadFunc()
{
if (CallNumber == Infinite)
while(Alive)
SleepAndRun();
else
while(repeat_count--)
SleepAndRun();
}
public:
static const long Infinite = -1L;
Timer(){}
Timer(const std::function<void(void)> &f) : funct (f) {}
Timer(const std::function<void(void)> &f,
const unsigned long &i,
const long repeat = Timer::Infinite) : funct (f)
{
interval(std::chrono::milliseconds(i)),
CallNumber(repeat) {}
}
void Start(bool Async = true)
{
if(IsAlive())
return;
Alive = true;
repeat_count = CallNumber;
if(Async)
Thread = std::thread(ThreadFunc, this);
else
this->ThreadFunc();
}
void Stop()
{
Alive = false;
Thread.join();
}
void SetFunction(const std::function<void(void)> &f)
{
funct = f;
}
bool IsAlive() const {return Alive;}
void RepeatCount(const long r)
{
if(Alive)
return;
CallNumber = r;
}
long GetLeftCount() const {return repeat_count;}
long RepeatCount() const {return CallNumber;}
void SetInterval(const unsigned long &i)
{
if(Alive)
return;
interval = std::chrono::milliseconds(i);
}
unsigned long Interval() const {return interval.count();}
const std::function<void(void)> &Function() const
{
return funct;
}
};
#endif
\ifndef定时器
#定义定时器
#包括
#包括
班级计时器
{
标准:螺纹;
bool-Alive=false;
长呼叫号码=-1L;
长重复计数=-1L;
std::chrono::毫秒间隔=std::chrono::毫秒(0);
std::function funct=nullpointr;
void SleepAndRun()
{
std::this_thread::sleep_for(interval);
如果(活着)
函数();
}
void ThreadFunc()
{
if(CallNumber==无限)
(活着时)
sleep和run();
其他的
while(重复计数--)
sleep和run();
}
公众:
静态常数长无穷=-1L;
计时器(){}
计时器(const std::function&f):funct(f){}
定时器(常数标准::函数和f,
const unsigned long&i,
const long repeat=计时器::无限):函数(f)
{
时间间隔(std::chrono::毫秒(i)),
呼叫号码(重复){}
}
无效启动(bool Async=true)
{
if(IsAlive())
返回;
活着=真;
重复计数=呼叫号码;
如果(异步)
Thread=std::Thread(ThreadFunc,this);
其他的
此->ThreadFunc();
}
无效停止()
{
活着=假;
Thread.join();
}
void SetFunction(const std::function&f)
{
funct=f;
}
bool IsAlive()常量{return Alive;}
无效重复计数(常数长r)
{
如果(活着)
返回;
CallNumber=r;
}
long GetLeftCount()常量{return repeat_count;}
long RepeatCount()常量{return CallNumber;}
void SetInterval(常量无符号长(&i)
{
如果(活着)
返回;
间隔=标准时间:时间:毫秒(i);
}
无符号长间隔()常量{return Interval.count();}
常量std::函数和函数()常量
{
返回函数;
}
};
#恩迪夫
<>如果有人能帮助我,我会非常感激,谢谢。 < p>第一个错误告诉你,<代码>零ultPruts<代码>没有定义。你可能是指使用
Timer(const std::function<void(void)> &f,
const unsigned long &i,
const long repeat = Timer::Infinite) : funct (f)
{
interval(std::chrono::milliseconds(i)),
CallNumber(repeat) {}
}
定时器(const std::function&f,
const unsigned long&i,
const long repeat=计时器::无限):函数(f)
{
时间间隔(std::chrono::毫秒(i)),
呼叫号码(重复){}
}
您可能想要的是:
Timer(const std::function<void(void)> &f,
const unsigned long &i,
const long repeat = Timer::Infinite) : funct (f),interval(i), CallNumber(repeat)
{}
定时器(const std::function&f,
const unsigned long&i,
const long repeat=Timer::Infinite):函数(f)、间隔(i)、调用号(repeat)
{}
它是nullptr
,而不是nullpointr
:)如果您在此处发布,请确保您的代码是可编译的-尤其是,包括所有可编译的标题。您是使用g++
还是gcc
进行编译的?在使用C++语言时更喜欢使用<代码> G++<代码>。
Timer(const std::function<void(void)> &f,
const unsigned long &i,
const long repeat = Timer::Infinite) : funct (f),interval(i), CallNumber(repeat)
{}