I know the usual cause for this message. However, I don't think that's happening here unless I'm missing something. I think the problem is cropping up because I'm deriving from an abstract base with a template class and it's not resolving all the methods because of that. The trouble is, I don't know how to fix it. I normally try not to mix templates and inheritance, but in this case I need fixed size array buffers and the only other way I know to accomplish this is to use the preprocessor rather than the compiler w/ templates. (Forgive any bugs in the code, I haven't even had a chance to test the proof of concept yet because it won't compile)
I get this error (clipped slightly):
In function `pool::MemoryPool::MemoryPool()':
MemoryPool.hpp:11: undefined reference to `vtable for pool::MemoryPool'
undefined reference to `typeinfo for pool::MemoryPool'
I've already tried every combination of constructors and destructors (virtual and non) in MemoryPool and StaticMemoryPool to no avail.
Any help?
Thanks in advance.
here's the code:
struct MemoryPool {
virtual void* alloc(const size_t size)=0;
virtual void freeAll()=0;
virtual void* next();
virtual size_t capacity()=0;
virtual size_t used()=0;
};
template<size_t C> class StaticMemoryPool : public MemoryPool {
uint8_t _heap[C];
uint8_t *_next;
public:
void* alloc(const size_t size) override {
if(used()+size>=C)
return nullptr;
void* result = _next;
_next+=size;
return result;
}
void freeAll() override {
_next = _heap;
}
void *next() override {
return _next;
}
size_t capacity() override { return C; }
size_t used() override {return _next-_heap;}
StaticMemoryPool() : _next(_heap) {}
~StaticMemoryPool() {}
};
Aucun commentaire:
Enregistrer un commentaire