KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to write a custom STL allocator that is derived from std::allocator , but somehow all calls to allocate() go to the base class. I have narrowed it down to this code: template <typename T> class a : public std::allocator<T> { public: T* allocate(size_t n, const void* hint = 0) const { cout << "yo!"; return 0; } }; int main() { vector<int, a<int>> v(1000, 42); return 0; } I expect "Yo!" to get printed, followed by some horrible error because I don't actually allocate anything. Instead, the program runs fine and prints nothing. What am I doing wrong? I get the same results in gcc and VS2008.
Tags (comma-separated)
Save Edits
Cancel