Hey, I've been struggling to setup a list object for a custom class I've made... Basically I don't know how to use the allocator class.
Could someone please help with an example and perhaps a short explanation for a custom class called Object?
I tried sumat like this (and failed)...
1 2 3
allocator<Object> objectAlloc;
std::list<Object, objectAlloc> objectList;
//Compiler was forcing me to start with std::list even though i was using namespace std.
1) default allocator for list<T> is std::allocator<T>, so first line is unnessesary and actually wrong.
Correct way to do that is: list<Object, allocator<Object>> objectList;, but you should be fine just with list<Object> objectList;
2) probably you are forced to use std::list because of name collision.
3) Your Object class should be either TriviallyCopyable or have a custom copy constructor;
4) Post errors here.
Right... I haven't yet made a copy constructor for my Object class, but I tried just using list<Object> objectList; but the compiler wouldn't accept it. Would the copy construct be why?