I keep getting expected primary expression when trying to pass a template parameter to a function call..
My Error looks like:
In PtrAllocator<T, Pool>::allocate(PtrAllocator<T, Pool>::size_type, const void*)': expected primary-expression before '>' token
In PtrAllocator<T, Pool>::max_size() const': expected primary-expression before '>' token
My code looks like:
template<typename T, typename Pool>
class PtrAllocator : public BasicAllocator<T>
{
private:
Pool pool;
public:
typedef typename BasicAllocator<T>::pointer pointer;
typedef typename BasicAllocator<T>::size_type size_type;
typedef typename BasicAllocator<T>::value_type value_type;
template<typename U>
struct rebind {typedef PtrAllocator<U, Pool> other;};
PtrAllocator(Pool&& pool) : pool(pool) {}
pointer allocate(size_type n, const void* hint = 0) {return static_cast<pointer>(pool.allocate<T>(n, hint));}
void deallocate(void* ptr, size_type n) {pool.deallocate(static_cast<pointer>(ptr), n);}
size_type max_size() const {return pool.max_size<T>();}
};
class Pool
{
public:
template<typename T>
void* allocate(std::size_t n, const void* hint = 0) {return ::operator new(n * sizeof(T));}
template<typename T>
void deallocate(T* ptr, std::size_t n) {::operator delete(ptr);}
template<typename T>
std::size_t max_size() const {return std::numeric_limits<std::size_t>::max() / sizeof(T);}
};
int main()
{
PtrAllocator<int, Pool> alloc = PtrAllocator<int, Pool>(Pool());
std::vector<int, PtrAllocator<int, Pool>> v(alloc);
v.resize(1000); //this line is causing the error.
}
The errors happen when PtrAllocator::allocate
calls Pool::allocate
. The same thing happens to max_size
but does not happen to deallocate
.
Any ideas why it won't let me specify the template parameter?