How do I setup a list?

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. 
Last edited on
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.
Last edited on
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?
Nope, if you doesn't have copy constructor it will lead to errors in runtime, not compile-time.
Post exact error here.
I've added a copy constructor and now my compiler (MS Visual Studio 2012) gives the error
IntelliSence: list is not a template
 
list<Object> objectList;


Object's copy constructor:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Object::Object(const Object& copy){
	id = copy.getID();

	delete name; //Delete all pointer style variables
	delete type;
	delete image;
	delete polygon;
	char* name = copy.getName(); //Uses C style strings
	char* type = copy.getType();
	char* image = copy.getImage();
	Polygon polygon = new Polygon(copy.getPolygon()); //Call Polygon's Copy constructor

	size[0] = copy.getSizeX();
	size[1] = copy.getSizeY();
	position[0] = copy.getPositionX();
	position[1] = copy.getPositionY();
}
did you include <list>? Did you try to do std::list ?
std::list<...> works, how come? (I am using namespace std)
Probably there is some other type named "list" in global namespace.
Fair enough... So, question: Answered
Thanks guys
Topic archived. No new replies allowed.