I am trying to implement thread-safe queue adapter for std::queue
This is an interface:
template <typename T>
class ThreadSafeQueueIT {
public:
virtual void push( const T& value ) = 0;
virtual void push( T&& value ) = 0;
virtual bool empty() = 0;
virtual T& front() = 0;
virtual void pop() =0;
};
This is queue template implementation:
template <class T>
class ThreadSafeQueue : public ThreadSafeQueueIT<T>{
private:
std::mutex mutex_;
std::queue<T> queue_;
public:
ThreadSafeQueue();
void push(const T &value) override;
void push(T &&value) override;
bool empty() override;
T &front() override;
void pop() override;
};
template <typename T>
void ThreadSafeQueue<T>::push(const T &value) {
std::lock_guard<std::mutex>(mutex);
queue_.push(value);
}
template <typename T>
void ThreadSafeQueue<T>::push(T &&value) {
std::lock_guard<std::mutex>(mutex);
queue_.push(value);
}
template <typename T>
bool ThreadSafeQueue<T>::empty() {
std::lock_guard<std::mutex>(mutex);
return queue_.empty();
}
template <typename T>
T &ThreadSafeQueue<T>::front() {
std::lock_guard<std::mutex>(mutex);
return queue_.front();
}
template <typename T>
void ThreadSafeQueue<T>::pop() {
std::lock_guard<std::mutex>(mutex);
queue_.pop();
}
One of my interfaces has this virtual method:
virtual ThreadSafeQueue<std::shared_ptr<Json>> & getMessages() = 0;
And during compilation I get following error:
error: ‘ThreadSafeQueue’ does not name a type
virtual ThreadSafeQueue<std::shared_ptr<Json>> & getMessages() = 0;
Why is this happening?
Aucun commentaire:
Enregistrer un commentaire