[英]Request for member 'start' in 'processingThread', which is of non-class type
我編寫了一個名為ProcessingThread的類,我在共享指針的幫助下傳遞了一個boost:循環緩沖區:
#ifndef PROCESSING_THREAD_H__
#define PROCESSING_THREAD_H__
#ifndef BOOST_ALL_DYN_LINK
#define BOOST_ALL_DYN_LINK
#endif
#include <bitset>
#include <thread>
#include "boost/circular_buffer.hpp"
using namespace boost;
class ProcessingThread{
public:
ProcessingThread(std::shared_ptr<circular_buffer<std::bitset<32>>> cBuffer) : circularBuffer(cBuffer), processingThread() {}
~ProcessingThread();
void start();
private:
void threadMain();
std::shared_ptr<circular_buffer<std::bitset<32>>> circularBuffer;
std::thread processingThread;
};
#endif
通過以下實現:
#include "processingThread.h"
ProcessingThread::~ProcessingThread(){
if(this->processingThread.joinable()){
this->processingThread.join();
}
}
void ProcessingThread::start(){
this->processingThread = std::thread(&ProcessingThread::threadMain, this);
}
void ProcessingThread::threadMain(){
//TODO some stuff
}
最后,我創建了一個類實例並調用start()。 這是出現錯誤的地方:
#include <bitset>
#include <iostream>
#include "boost/circular_buffer.hpp"
#include "processingThread.h"
using namespace boost;
using namespace std;
int main(){
circular_buffer<bitset<32>> circularBuffer(4000);
ProcessingThread processingThread(std::shared_ptr<circular_buffer<bitset<32>>>(circularBuffer));
processingThread.start(); <--- error
}
錯誤說:
error: request for member ‘start’ in ‘processingThread’, which is of non-class type ‘ProcessingThread(std::shared_ptr<boost::circular_buffer<std::bitset<32ul> > >)’
這是使用'。'的典型錯誤。 當使用動態創建類時,而不是' - >',而不是這種情況。
我在這里錯過了什么?
你定義了一個函數!
ProcessingThread processingThread(
std::shared_ptr<circular_buffer<bitset<32>>>(circularBuffer) );
是一個函數,它有一個類型為std::shared_ptr<circular_buffer<bitset<32>>>
。 簡易解決方案
ProcessingThread processingThread(
std::shared_ptr<circular_buffer<bitset<32>>> { circularBuffer } );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.