나는 C++을 배우려고하기 때문에이 바보 같은 질문에 사과한다.이 기본적인 것을 얻으면 많은 것이 분명해진다. 나는 그것을하는 동안 C++을 가르치기위한 keylogger를 만드는 가이드를 따라 가고있다. . 그러나 설명은 너무 약한 정확히 지시 및 디버깅하려고 같은 프로그램을 작성 후 내가 얻을 :이 오류 메시지는 무엇을 말해 줍니까?
내 첫 번째 질문에 대해 사과|=== Build: Debug in test (compiler: GNU GCC Compiler) ===| :\example\test\test\Timer.h|14|error: 'nullpointr' was not declared in this scope| :\example\test\test\Timer.h||In constructor 'Timer::Timer(const std::function<void()>&, const long unsigned int&, long int)':| :\example\test\test\Timer.h|44|error: no match for call to '(std::chrono::milliseconds {aka std::chrono::duration<long long int, std::ratio<1ll, 1000ll> >}) (std::chrono::milliseconds)'| :\example\test\test\Timer.h|45|error: expression cannot be used as a function| |=== Build failed: 3 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
이 잘 구축되지 않은,하지만 난 어디 있는지 알고하지 않습니다 내 경험이 부족하기 때문에 시작해야합니다. 나는 실수 메시지가 나에게 말해야하는 것과 누군가 참조를 이해하는 방법을 알지 못한다. 그래서 'nullpointr'가이 범위에서 선언되지 않은 것처럼 누군가가이 몇 가지 메시지의 다른 의미를 설명 할 수 있다면 정말 감사하겠다. " 이미 물어보고 답변을 찾았지만 다른 사람이 오류가 없으므로이 헤더의 코드 만보아야한다고 가정합니다 ...? 여기에 내가 복사 한 코드를 들여했다 "{"와 "}"하지만 붙여 넣을 때 왼쪽 끝까지 그들의 대부분을 보여 주었다 (추한 코드에 대한 유감입니다 :
#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
사람이 나를 도울 수있는 경우 감사합니다. 감사합니다.
'nullptr'가 아닌'nullpointr'이 :) – Rakete1111
, 당신의 코드를 컴파일 가능한 있는지 확인 - 특히 모든 헤더를 #include를 그것은 그렇게 할 것입니다. –
'g ++'또는'gcc'를 사용하여 컴파일하고 있습니까? C++ 언어를 사용하고있을 때는'g ++'을 사용하기를 선호합니다. –