I think I should post the whole source code >_<" Somebody help me please... this is a very basic thing, isn't it?
Code:
template<typename T>class MemoryPool
{
private:
T *base;
unsigned short initial;
unsigned short increment;
unsigned int allocated;
public:
MemoryPool(unsigned short size)
{
base = NULL;
if((base = (T *)malloc(size * sizeof(T))) == NULL)
abort();
initial = size;
increment = 1;
allocated = size;
};
~MemoryPool()
{
free(base);
};
T *check(unsigned int offset)
{
while(offset >= allocated)
{
if((base = (T *)realloc(base, (allocated = ++increment * initial) * sizeof(T))) == NULL)
abort();
}
return base;
};
T *getBase()
{
return base;
};
};
template<typename T>class Stack : private MemoryPool<T>
{
private:
unsigned int offset;
public:
Stack(unsigned short size)
// ^---^ BAD?
{
//BAD: this->MemoryPool(size);
//BAD: (MemoryPool)this->MemoryPool(size);
//BAD: MemoryPool::MemoryPool(size);
};
};
int main(int argc, char **argv)
{
Stack<char> stk(10); // <--- error
getchar();
return 0;
}
Oops and the error:
Code:
D:\Documents and Settings\Audi Nugraha\Desktop\stack.cpp: In constructor `Stack<T>::Stack(short unsigned int) [with T = char]':
D:\Documents and Settings\Audi Nugraha\Desktop\stack.cpp:68: instantiated from here
D:\Documents and Settings\Audi Nugraha\Desktop\stack.cpp:58: error: no matching function for call to `MemoryPool<char>::MemoryPool()'
D:\Documents and Settings\Audi Nugraha\Desktop\stack.cpp:5: note: candidates are: MemoryPool<char>::MemoryPool(const MemoryPool<char>&)
D:\Documents and Settings\Audi Nugraha\Desktop\stack.cpp:16: note: MemoryPool<T>::MemoryPool(short unsigned int) [with T = char]