My question is how do I add this second argument in version allocate2?
I tried to insert : typename Pool_alloc<void>::const_pointer hint as 2nd argument but its not working and I'm getting
'Pool_alloc<T>::allocate2': unable to match function definition to an existing declaration
error
1 2 3 4 5
template<typename T>
typename Pool_alloc<T>::pointer Pool_alloc<T>::allocate(typename Pool_alloc<T>::size_type n, /* code for typename Pool_alloc<void>::const_pointer hint*/)
{
returnreinterpret_cast<typename Pool_alloc<T>::pointer>(::newchar[n * sizeof(T)]);
}
Ok I tried if I create allocate2 like this and it worked
1 2
template<typename U>
pointer allocate2(size_type n, typename Pool_alloc<U>::const_pointer hint = 0);
and than outside its class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
template<typename T>
using Pointer = typename Pool_alloc<T>::pointer;
template<typename T>
using Size_type = typename Pool_alloc<T>::size_type;
template<typename T>
using Const_pointer = typename Pool_alloc<T>::const_pointer;
template<typename T>
template<typename U>
Pointer<T> Pool_alloc<T>::allocate2(Size_type<T> n, Const_pointer<U> hint)
{
returnreinterpret_cast<Pointer<T>>(::newchar[n * sizeof(T)]);
}
But the problem is now I can pass all kinds of pointers as hint parameter not just constvoid*. How to make it so only Pool_alloc<void>::const_pointer is accepted?
Tnx for an answer. To answer your question its because I want to understand why the 1st way its not working, its not that important to get this to run using constvoid* without learning anything new
I think we have a winner!!! :D Tnx you so much for an answer JLBorges. I can see what I did wrong and tnx for improvements in my code. Will also think about them. Thanks!