Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. template <typename T>
  2. class Coordinate
  3. {
  4. public:
  5. T x_; ///< x_coordinate
  6. T y_; ///< y_coordinate
  7. };
  8.  
  9.  
  10. template<typename T>
  11. struct compare_x_coordinate
  12. {
  13. bool operator() (const Coordinate<T> &i,const Coordinate<T> &j)
  14. { return i.x_<j.x_; }
  15. } ;
  16.  
  17. template<typename T>
  18. struct compare_y_coordinate
  19. {
  20. bool operator() (const Coordinate<T> &i,const Coordinate<T> &j)
  21. { return i.y_<j.y_; }
  22. } ;
  23.  
  24.  
  25.  
  26.  
  27. template<typename T >
  28. void find_points(const std::vector<Coordinate<T> > &ptArray,
  29. Coordinate<T> &left,
  30. Coordinate<T> &right
  31. )
  32. {
  33. compare_x_coordinate<T> mycompare;
  34. std::vector<Coordinate<T> >::const_iterator it_max = std::max_element(ptArray.begin(), ptArray.end(), mycompare);
  35. int index_max = it_max-ptArray.begin();
  36.  
  37.  
  38. std::vector<Coordinate<T> >::const_iterator it_min = std::min_element(ptArray.begin(),ptArray.end(),mycompare);
  39. int index_min = it_min-ptArray.begin();
  40.  
  41. left = ptArray[index_min];
  42. right = ptArray[index_max];
  43. } ;
  44.  
  45.  
  46. int main(void)
  47. {
  48. std::vector<Coordinate<float> > ptArray;
  49. Coordinate<float> pt;
  50. pt.x_ = 20;
  51. pt.y_ = 15;
  52. ptArray.push_back(pt);
  53.  
  54. pt.x_ = 3;
  55. pt.y_ = 200;
  56. ptArray.push_back(pt);
  57.  
  58. pt.x_ = 7;
  59. pt.y_ = 2;
  60. ptArray.push_back(pt);
  61.  
  62. pt.x_ = 12;
  63. pt.y_ = 500;
  64. ptArray.push_back(pt);
  65.  
  66. Coordinate<float> left;
  67. Coordinate<float> right;
  68. find_points<float>(ptArray,left,right);
  69.  
  70. return 0;
  71. }
  72.  
  73. In function 'void find_points(), error: expect ';' before 'it_max'
  74. 'it_max' was not declared in this scope
  75.  
  76. typename std::vector<Coordinate<T> >::const_iterator it_max =
  77. std::max_element(ptArray.begin(), ptArray.end(), mycompare);
  78.  
  79. typename std::vector<Coordinate<T> >::const_iterator it_min =
  80. std::min_element(ptArray.begin(),ptArray.end(),mycompare);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement