Errors using lists

Object.cpp
1
2
3
4
5
6
7
8
9
10
11
12
#include "Object.h"

Object::Object(Object& copy){
	id = copy.getID();
	name	= copy.getName();
	type	= copy.getType();
	image	= copy.getImage();
	polygon	= new oPolygon(*copy.polygon);

	object_List.push_back(*this);
	numObjects++;
}


Object.h
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <list>
#include "oPolygon.h"

class Object{
public:
    Object(Object& copy); //Copy Constructor
private:
    static int numObjects;
    static std::list<Object> object_List;
    static std::list<Object>::iterator object_Iter;
    static std::list<Object>::const_iterator object_cIter;

};


(I have completed rest of class declarations and definitions and everything works perfectly except...)
This is all the relevant information to my error, hopefully someone wise enough would be able to explain why I get this thrown back in my face?


error C2558: class 'Object' : no copy constructor available or copy constructor is declared 'explicit'
Last edited on
Object(const Object &copy);


Also, this looks bad polygon = new oPolygon(*copy.polygon);
Last edited on
The source of the error as I think is the following statement

object_List.push_back(*this);

It requires that the following copy constructor

Object( const Object &copy );


of class Object would be declared as @ne555 already pointed out.
Right, cheers guys.

And @ne555 I think the polygon should be correct, the oPolygon is another object I have.

I do have another question though...
If a class contained a C style string, I'd need to copy it like this right?
1
2
name = new char[sizeof copy.name];
name = copy.name;
> the oPolygon is another object I have.
¿but why are you using dynamic allocation?


1
2
3
4
5
name = new char[sizeof copy.name]; //sizeof is computed at compile time
name = copy.name; //leak

name = new char[strlen(copy.name)+1];
strcpy(name, copy.name);
Ah... I see the problem there, thanks for that.
Last edited on
Topic archived. No new replies allowed.