The following codes can run very well in windows:
template <typename T>
class Coordinate
{
public:
T x_; ///< x_coordinate
T y_; ///< y_coordinate
};
template<typename T>
struct compare_x_coordinate
{
bool operator() (const Coordinate<T> &i,const Coordinate<T> &j)
{ return i.x_<j.x_; }
} ;
template<typename T>
struct compare_y_coordinate
{
bool operator() (const Coordinate<T> &i,const Coordinate<T> &j)
{ return i.y_<j.y_; }
} ;
template<typename T >
void find_points(const std::vector<Coordinate<T> > &ptArray,
Coordinate<T> &left,
Coordinate<T> &right
)
{
compare_x_coordinate<T> mycompare;
std::vector<Coordinate<T> >::const_iterator it_max = std::max_element(ptArray.begin(), ptArray.end(), mycompare);
int index_max = it_max-ptArray.begin();
std::vector<Coordinate<T> >::const_iterator it_min = std::min_element(ptArray.begin(),ptArray.end(),mycompare);
int index_min = it_min-ptArray.begin();
left = ptArray[index_min];
right = ptArray[index_max];
} ;
int main(void)
{
std::vector<Coordinate<float> > ptArray;
Coordinate<float> pt;
pt.x_ = 20;
pt.y_ = 15;
ptArray.push_back(pt);
pt.x_ = 3;
pt.y_ = 200;
ptArray.push_back(pt);
pt.x_ = 7;
pt.y_ = 2;
ptArray.push_back(pt);
pt.x_ = 12;
pt.y_ = 500;
ptArray.push_back(pt);
Coordinate<float> left;
Coordinate<float> right;
find_points<float>(ptArray,left,right);
return 0;
}
However, when it is compiled in Linux, the following errors occur:
In function 'void find_points(), error: expect ';' before 'it_max'
'it_max' was not declared in this scope
Any ideas? Thanks.