1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Confusion with Template Arguments

Discussion in 'C++' started by vkaul1, Jun 23, 2010.

  1. vkaul1

    vkaul1 New Member

    Jun 23, 2010
    Likes Received:
    Trophy Points:
    I was using double iterators

    for(map<int,int>::iterator it=endPoints.begin() ; it != endPoints.end();it++){
    	for(map<int,int>::iterator it1=it+1; it1 != endPoints.end();it1++){
    		for (i=0;i<(XSize*YSize);i++){
    		float endPointsDistance = euclideanDistanceCheck2D(input,output,euc_output,XSize,YSize,Intensity,heapSize,boundaryPoints,(*it).first);	
    		if( endPointsDistance < 2*lambda){
    			for (i=0;i<(XSize*YSize);i++){
    			float verificationDistance = euclideanDistanceCheck2D(input,output,euc_output,XSize,YSize,Intensity,heapSize,boundaryPoints,(*it).first);
    			if( verificationDistance > (endPointsDistance + lambda - errorTolerance)  && verificationDistance < (endPointsDistance + lambda + errorTolerance)){
    				detectedCurve.insert(detectedCurve.end(), minimalPath.begin(), minimalPath.end());
    and it is giving two errors for the use of iterators it and it1
    ------------------Configuration: test_geodesic - Win32 Debug--------------------
    F:\WD_Windows_Tools\C\James_tsai_documents\test_geodesic\Geodesic_June_23_2010.cpp(169) : error C2784: 'class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> __cdecl std::eek:perator +(_D,const class std::reverse_iterator<_RI,_Ty,_Rt,_Pt,_D> &)' : could not
    deduce template argument for '' from 'class std::_Tree<int,struct std::pair<int const ,int>,struct std::map<int,int,struct std::less<int>,class std::allocator<int> >::_Kfn,struct std::less<int>,class std::allocator<int> >::iterator'
    F:\WD_Windows_Tools\C\James_tsai_documents\test_geodesic\Geodesic_June_23_2010.cpp(169) : error C2676: binary '+' : 'class std::_Tree<int,struct std::pair<int const ,int>,struct std::map<int,int,struct std::less<int>,class std::allocator<int> >::_Kf
    n,struct std::less<int>,class std::allocator<int> >::iterator' does not define this operator or a conversion to a type acceptable to the predefined operator
    Error executing cl.exe.

    I can't understand these new errors.

    For example, if we have an array and I want to examine some condition that involves pairs of elements from the array, I will first start the outer loop from the first element and in the inner loop examine second to last elements. Similarly in the next outer loop iteration I will have to start from second element and the inner loop will proceed from third to last element.

    So instead of array here, I have a map and I want to do the same. I need two iterators with the second iterator going one element ahead of the first.
    It is surprising that it++ in the for loop is alright but it1=it+1 is not ok. Why not?

Share This Page