Allocator Compiler Error on GCC 3.4.4
Hello:
I have been trying to write a custom allocator after reading about
them in Effective STL. I found a "template" for allocators and
inserted my own code.
When I compiled it on VC++ 8, it worked fine and dandy. However, on
GCC 3.4.4 it gives me two errors:
stlTest.cpp:10: error: no matching function for call to
`WorstAllocator<int>::WorstAllocator(WorstAllocator<int>)'
It appears as though the code is looking for a copy ctor with the
wrong signature. I get this error when trying to create a vector<int,
WorstAllocator<int> >
I have the following code:
#include "memory.hpp"
#include <cstddef>
#include <numeric>
template<typename T>
class WorstAllocator {
public :
// typedefs
typedef T value_type;
typedef value_type * pointer;
typedef const value_type * const_pointer;
typedef value_type & reference;
typedef const value_type & const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
const static size_type MEMORY_SIZE = 70000;
// convert an allocator<T> to allocator<U>
template<typename U>
struct rebind {
typedef WorstAllocator<U> other;
};
inline explicit WorstAllocator() {}
inline ~WorstAllocator() {}
inline explicit WorstAllocator(WorstAllocator const&) {}
template<typename U>
inline explicit WorstAllocator(WorstAllocator<U> const&) {}
// address
inline pointer address(reference r) { return &r; }
inline const_pointer address(const_reference r) { return &r; }
// memory allocation
inline pointer allocate(size_type cnt,
void * = 0) {
return reinterpret_cast<T *>(
WorstMemory<MEMORY_SIZE>::allocate(static_cast<int>(cnt *
sizeof(T))));
}
inline void deallocate(pointer p, size_type) {
WorstMemory<MEMORY_SIZE>::deallocate(p);
}
// size
inline size_type max_size() const {
return MEMORY_SIZE / sizeof(T);
}
// construction/destruction
inline void construct(pointer p, const T& t) { new(p) T(t); }
inline void destroy(pointer p) { p->~T(); }
inline bool operator==(WorstAllocator const&) { return true; }
inline bool operator!=(WorstAllocator const& a) { return !
operator==(a); }
}; // end of class Allocator
I am hoping that these are simple issues. Any help would be
appreciated.
I wanted to see if I could hook a custom allocator up to a Worst Fit
memory manager I wrote long ago. It works great with VC++8!
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]