attempt to copy from a singular iterator

Hi,

I have the following lines in the constructor of a class:
1
2
3
4
5
cout<<"1\n";
contourPoint s(v);
cout<<"2\n";
seed = contourPoint(v);
cout<<"3\n";


where, contourPoint is a structure I defined (contains a valid copy constructor as well). the program runs just fine in release mode, but in the debug mode, I get the following error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1
2
/usr/include/c++/4.2.1/debug/safe_iterator.h:164:error: attempt to copy 
    from a singular iterator.

Objects involved in the operation:
iterator "this" @ 0x0x7fff5fbfdb28 {
type = N11__gnu_debug14_Safe_iteratorISt23_Rb_tree_const_iteratorISt4pairIiiEENSt7__debug3setIS3_St4lessIS3_ESaIS3_EEEEE (mutable iterator);
  state = singular;
}
iterator "other" @ 0x0x7fff5fbfda58 {
type = N11__gnu_debug14_Safe_iteratorISt23_Rb_tree_const_iteratorISt4pairIiiEENSt7__debug3setIS3_St4lessIS3_ESaIS3_EEEEE (mutable iterator);
  state = singular;
}
Abort


It doesnt even give me the line number, so I printed 1,2,3 to see what line it breaks only on the commandline.

Any ideas as to how to fix this ? Googling didnt help me much here.

Thanks
closed account (yUq2Nwbp)
and what type has your seed??
Could you list your class contourPoint? It seems to happen in one of its members, probably the red-black tree.

Btw. if you use cerr instead of cout you get unbuffered output so it will be displayed "immediately". Alternatively you can an endl or flush.

1
2
3
4
5
6
cout<<"1\n";
cerr<<"1\n";
// or
cout<<"1" << endl;
// or
cout<<"1\n" << flush;


(see also: http://www.cplusplus.com/reference/iostream/ )
Last edited on
seed is the member variable of the class whose constructor is being called. it is of 'contourPoint' class.
here is the contour point class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//================================================================
// a point on the contour : can only exist on a vertex or an edge
class contourPoint{

	bool isVertex;

	int V;

	set<Edge>::const_iterator edge;
	double alpha;

public:
	contourPoint(){
		V = -1;
		isVertex = true;
	}
	contourPoint(int v_){
		V = v_;
		isVertex = true;
	}
    contourPoint::contourPoint(const contourPoint& p) {
        V = p.get_V();
        isVertex = p.is_onVertex();
    }
	contourPoint(set<Edge>::const_iterator ed, double alp){
		V = -1;
		isVertex = false;
		edge = ed;
		alpha = alp;
	}


could it be that the second constructor does not initialize the iterator edge which creates a problem ? I dont want to use the iterator if I call the second constructor. Is there a default/null value I can assign to the iterator ?
/usr/include/c++/4.2.1/debug/safe_iterator.h:164:error: attempt to copy from a singular iterator.

This line says that you try to do something like this:
1
2
3
set<Edge>::const_iterator someUninitializedIterator;

contourPoint cp (someUninitializedIterator, 1.0); // here you pass uninitalized iterator 


Could you post the lines where you create the contourPoint?

You could also refactor the constructor:

1
2
3
4
5
6
7
8
9
class contourPoint{

//...
	contourPoint(set<Edge>::const_iterator ed, double alp)
        : V(-1)
        , isVertex(false)   
        , edge(ed)
        , alpha(alp)
       {}


Because in your version there is first an uninitalized iterator created which is later assigned a valid iterator. Maybe your compiler complains about this.
Topic archived. No new replies allowed.