cannot deduce template arguments

I was using stl maps for the first time and iterator to go along with them. Compiling in VC++ 6 I get following errors which I can't seem to solve at all.
Any help will be appreciated. The main problem is in this portion of the code
1
2
3
4
5
6
7
8
9
10
11
12
13
map<int,int>::iterator it;

	while ( stopDetection == false ) {
		

		for(int i=0;i<(XSize*YSize);i++){
			input[i]=1000000.0f;
		}
       
  
		for(it=sourcePoints.begin() ; it < sourcePoints.end();it++){
			input[*it->first]=0.0f;
		}


I have attached the compilation errors and the complete code below also.

Compiling...
Geodesic_June_22_2010.cpp
F:\WD_Windows_Tools\C\James_tsai_documents\test_geodesic\Geodesic_June_22_2010.cpp(113) : error C2784: 'bool __cdecl std::operator <(const class std::multimap<_K,_Ty,_Pr,_A> &,const class std::multimap<_K,_Ty,_Pr,_A> &)' : could not deduce template 
argument for 'const class std::multimap<_K,_Ty,_Pr,_A> &' 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_22_2010.cpp(113) : error C2784: 'bool __cdecl std::operator <(const struct std::pair<_T1,_T2> &,const struct std::pair<_T1,_T2> &)' : could not deduce template argument for 'cons
t struct std::pair<_T1,_T2> &' 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_22_2010.cpp(113) : error C2784: 'bool __cdecl std::operator <(const struct std::pair<_T1,_T2> &,const struct std::pair<_T1,_T2> &)' : could not deduce template argument for 'cons
t struct std::pair<_T1,_T2> &' 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_22_2010.cpp(113) : 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
F:\WD_Windows_Tools\C\James_tsai_documents\test_geodesic\Geodesic_June_22_2010.cpp(114) : error C2100: illegal indirection
Error executing cl.exe.

Geodesic_June_22_2010.obj - 26 error(s), 0 warning(s)



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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "pheap.h"
float& max(float &a,float &b);
float& min(float &a,float &b);
int findSource(int p, float* geodesic,int xsize,vector<int> &minimalPath);
int signedDistanceTransform2D(float *in,float *out,float *euc_out,int xsize,int ysize,float *phi,int &heapSize,long *boundaryPoints, int &source, vector<int> &minimalPath);
float euclideanDistanceCheck2D(float *in,float *out,float *euc_out,int xsize,int ysize,float* Intensity,int &heapSize,long *BoundaryPoints,int previous); 
using namespace std;

int main()
{   //int XSize = 457,YSize = 1027;
	//int XSize=782, YSize=737;
	//int XSize=281, YSize=219;
	int XSize=256, YSize=256;
    long    gridSize=XSize*YSize;
    float *input=new float[gridSize];
	float *output=new float[gridSize];
	float *euc_output=new float[gridSize];
	long *boundaryPoints=new long[gridSize/10]; 
	int heapSize=0;
	float *Intensity=new float[gridSize];
	//Number of Source Points
	const int SPCOUNT=gridSize/1000;
	bool stopDetection = false;
	int keyPointIterations = 1;
	int keyPointSource = 0;
	const float lambda = 30.000f; 
    const float errorTolerance = 0.1f * lambda;
    
	// Vector for Fast March Source Points
	map<int,int> sourcePoints;
	// Vector for the Curve Location
	vector<int> detectedCurve;
	//Vector for the last minimal path
	vector<int> minimalPath;
	
	//reserve space for  source points
//	sourcePoints.reserve(SPCOUNT);

	//reserve space for a detected Curve
	detectedCurve.reserve(gridSize/10);
	

	
	
	// Initial Source Point
	//const int initialpoint=  21370;
    //const int initialpoint=  111240;
	const int initialPoint=  26479;

	//Initializing Source Points
	//sourcePoints.push_back(initialpoint);

    
	for(int i=0;i<(XSize*YSize);i++){
		input[i]=1000000.0f;
	}

  //setting distance at initial crack point to zero	26479
		input[initialPoint]=0.0f;
	
    
 // Reading the Potential function values on the Image ( in this case Intensity values)
  FILE *file;

  file = fopen("OpenCurvenb.txt", "r");


	if(file==NULL) {
		printf("Error: can't open file.\n");
		return 1;
	}
	else {
		printf("File opened successfully.\n");

		int i = 0 ;    
    
		while(!feof(file)) { 
     //loop through and store the numbers into the array 
		fscanf(file, "%f", &Intensity[i]);
        i++;
		}
	
		printf("Number of numbers read: %d\n\n", i);
		printf("The numbers are:\n");

		fclose(file);
	}  
    int firstKeyPoint= signedDistanceTransform2D(input, output, euc_output, XSize, YSize, Intensity, heapSize, boundaryPoints, keyPointSource, minimalPath);
	//Append minimalPath to curveDetected
	detectedCurve.insert(detectedCurve.end(), minimalPath.begin(), minimalPath.end());
	//Add first Key Point and its Source(initial point) and the initial point and the first key Point as the key, values pairs in the map
	sourcePoints[firstKeyPoint]=initialPoint;
	sourcePoints[initialPoint]=firstKeyPoint;
    
	map<int,int>::iterator it;

	while ( stopDetection == false ) {
		

		for(int i=0;i<(XSize*YSize);i++){
			input[i]=1000000.0f;
		}
       
  
		for(it=sourcePoints.begin() ; it < sourcePoints.end();it++){
			input[*it->first]=0.0f;
		}
    
		int secondKeyPoint= signedDistanceTransform2D(input, output, euc_output, XSize, YSize, Intensity, heapSize, boundaryPoints, keyPointSource, minimalPath);
        
        cout<<"KeyPointSource"<<keyPointSource << endl;
		//sourcePoints[secondKeyPoint]= keyPointSource;
		for (i=0;i<(XSize*YSize);i++){
			input[i]=1000000.0f;
		}

       // Select the source point of the keyPointSource as the initial point  
		for (i=0;i<sourcePoints.size();i++){
			input[sourcePoints[keyPointSource]]=0.0f;
		}
		   // Take out the Source Point that was closest to SecondKeypoint from the sourcePoints set
		   //input[keyPointSource]= 1000000.0f;
		float keyPointDistance = euclideanDistanceCheck2D(input,output,euc_output,XSize,YSize,Intensity,heapSize,boundaryPoints,secondKeyPoint);
        cout<<"Test 3"<<endl;
		if ( keyPointDistance > (2.0f*lambda - errorTolerance)  &&  keyPointDistance < (2.0f*lambda + errorTolerance)  ) {
			
          // Add the secondKeyPoint to the sourcePoints map
			 sourcePoints[secondKeyPoint]= keyPointSource;
             cout<<"Iterations"<<endl;
			 // Append minimalPath to CurveDetected
			 detectedCurve.insert(detectedCurve.end(), minimalPath.begin(), minimalPath.end());
			 // Make the secondKeyPoint the firstKeyPoint now
			//firstKeyPoint = secondKeyPoint ;
			keyPointIterations++;
		}  
		else { 
				stopDetection = true ; 
				if ( keyPointIterations == 1) {
					// Empty Detected Curve 
					detectedCurve.clear();
					
					cout<< "No curve detected" << endl;

				}
		}
	}

     for(i=0;i<sourcePoints.size();i++){
	    cout<<sourcePoints[i]<<endl;
	}
    delete [] input;
	delete [] output;
	delete [] euc_output;
	delete [] Intensity;
	delete [] boundaryPoints;
    return 0;
}
Try it without the '*'. it->first should already be giving you the key I think.
Try changing
it < sourcePoints.end()
to
it != sourcePoints.end()

--Rollie
Thanks for your help.
I tried it, it works apart from some warnings.
But now I modified the code and it gives some new errors. I will just show the section I modified
I was using double iterators
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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++){
													input[i]=1000000.0f;
												}	
												input[(*it1).first]=0.0f;
												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++){
													   input[i]=1000000.0f;
													 }
                                                     input[(*it1).second]=0.0f; 
												     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--------------------
Compiling...
Geodesic_June_23_2010.cpp
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::operator +(_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(map<int,int>::iterator it1=it+1


binary + is supported only for random access iterators. map iterators are not random access.

you probably don't want do declare another variable named "it" there, since it shadows
the one from the outer loop.
But I want the other iterator in the inner loop to start from 1 after the outerloop till the end.
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?
vkaul1 wrote:
It is surprising that it++ in the for loop is alright but it1=it+1 is not ok. Why not?


jsmith wrote:
binary + is supported only for random access iterators. map iterators are not random access.


Because you could technically put any number other than 1 there. They can't overload + to work only with 1.
So

1
2
3
4
5
6
7
8
9
typedef std::map<int,int>::iterator Iter;

for( Iter outer = ... ) {
    Iter inner( outer );
    if( outer != endPoints.end() )   // Fixing your bug
        ++outer;
    for( ; inner != endPoints.end(); ++inner )
         // ...
}
Topic archived. No new replies allowed.