6
I am making an application that sorts an object vector. These objects are Cartesian points, defined in the following class:
class CartesianPoint {
private:
int x; // Coordinate X of a pin or a wire part on a cartesian plan
int y; // Coordinate Y of a pin or a wire part on a cartesian plan
public:
CartesianPoint();
CartesianPoint(const CartesianPoint& orig);
virtual ~CartesianPoint();
int getX() const {
return x;
}
int getY() const {
return y;
}
CartesianPoint(int x, int y) :
x(x), y(y) {
}
To sort, I am using the Sort function as follows:
int main()
{
int i;
CartesianPoint *a = new CartesianPoint(10, 13), *b = new CartesianPoint(32, 1), *c = new CartesianPoint(5, 29), *d = new CartesianPoint(12, 6), *e = new CartesianPoint(21, 100);
CartesianPoint myPoints[] = {*a, *b, *c, *d, *e};
std::vector<CartesianPoint> myvector(myPoints, myPoints+8);
// using function as comp
std::sort(myvector[0], myvector.end(), myfunction);
// print out content:
std::cout << "myvector contains:";
for (i = 0; i < 8; i++)
std::cout << ' ' << '(' << myvector[i].getX() << ',' << myvector[i].getY() << ')';
std::cout << '\n';
return 0;
}
where "myfunction" is the function that sorts points decreasing from x:
CartesianPoint* myfunction(CartesianPoint *a, CartesianPoint *b) {
if(a->getX() > b->getX())
return (a);
else
return (b);
}
The problem you’re giving is in the function call sort
:
sort.cpp:33:5: error: no matching function for call to 'sort'
std::sort(myvector[0], myvector.end());
What is may be wrong?
Where are the includes? Edit your code here and show us, please!
– Christian Felipe