I have this class MediaRecorder.cpp
with the methods stopRecording
, startRecording
and requestData
. I tried to add another method that calls requestData
but I can't make it work.
首先,我尝试了:
MediaRecorder.h
...
void SendData(int);
ExceptionOr<void> startRecording(Optional<int>);
ExceptionOr<void> stopRecording();
ExceptionOr<void> requestData();
...
MediaRecorder.cpp
...
void MediaRecorder::SendData(int timeslice)
{
using namespace std::literals::chrono_literals;
while (!s_finished)
{
std::cout << "Call RequestData()\n";
this->requestData();
std::this_thread::sleep_for(timeslice);
}
}
ExceptionOr<void> MediaRecorder::startRecording(Optional<int> timeslice)
{
//...
if (timeslice)
{
std::thread th1 (SendData, timeslice.value());
th1.join();
}
return { };
}
ExceptionOr<void> MediaRecorder::stopRecording()
{
s_finished = true;
//...
return { };
}
ExceptionOr<void> MediaRecorder::requestData()
{
//...
return { };
}
...
错误:
reference to non-static member function must be called
std::thread th1 (SendData, timeslice.value());
我也尝试过:
// MediaRecorder.h
ExceptionOr<void> startRecording(Optional<int>);
ExceptionOr<void> stopRecording();
ExceptionOr<void> requestData();
// MediaRecorder.cpp
static void SendData(int timeslice)
{
using namespace std::literals::chrono_literals;
while (!s_finished)
{
std::cout << "Call RequestData()\n";
this->requestData();
std::this_thread::sleep_for(timeslice);
}
}
错误:
invalid use of 'this' outside of a non-static member function
this->requestData();