I moved out the methods implementation from my class and caught the following error:
use of class template requires template argument list
for method whitch doesn't require template type at all... (for other methods all ok)
Class
template<class T> class MutableQueue { public: bool empty() const; const T& front() const; void push(const T& element); T pop(); private: queue<T> queue; mutable boost::mutex mutex; boost::condition condition; };
Wrong implementation
template<> //template<class T> also incorrect bool MutableQueue::empty() const { scoped_lock lock(mutex); return queue.empty(); }
In C++ this can be achieved using template parameters. A template parameter is a special kind of parameter that can be used to pass a type as argument: just like regular function parameters can be used to pass values to a function, template parameters allow to pass also types to a function.
You cannot give default arguments to the same template parameters in different declarations in the same scope. The compiler will not allow the following example: template<class T = char> class X; template<class T = char> class X { };
Templates can be template parameters. In this case, they are called template parameters. The container adaptors std::stack, std::queue, and std::priority_queue use per default a std::deque to hold their arguments, but you can use a different container.
1) A template template parameter with an optional name. 2) A template template parameter with an optional name and a default. 3) A template template parameter pack with an optional name.
It should be:
template<class T> bool MutableQueue<T>::empty() const { scoped_lock lock(mutex); return queue.empty(); }
And if your code is that short, just inline it, as you can't separate the implementation and header of a template class anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With