Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8900465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:06:17+00:00 2026-06-15T01:06:17+00:00

I have a simple Position struct: struct Position { int x; int y; };

  • 0

I have a simple Position struct:

struct Position
{
    int x;
    int y;
};

I also have a list of Positions:

std::list<Position> positons;

I’m trying to sort the list using list::sort() and need to define operator< for Positions objects. I tried keeping it simple creating something like:

bool operator<(const Position& one, const Position& two)
{
    return one.x < two.x && one.y < two.y;
}

But that doesn’t work. How do I determine that one class/struct object as a whole is less than another? How would I do it for my Position struct?

EDIT When I call positions.sort(), I get a debug assertion failed which says:
Expression: invalid operator<

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:06:18+00:00Added an answer on June 15, 2026 at 1:06 am

    You can sort by x and then by y. Also define it as free function:

    bool function(const Position& one, const Position& two)
    {
        return one.x < two.x || (one.x == two.x && one.y < two.y);
    }
    

    Or as operator:

    bool operator<(const Position& other)const
    {
        return x < other.x || (x == other.x && y < other.y);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple class public class Position{ int x; int y; Position(int x,int
I have a simple struct: typedef struct { void *things; int sizeOfThings; } Demo;
I have a simple jQuery function--detailed below-- that I'm using to manipulate the position
I have simple class with width and height member fields which define number of
I have simple element: <a id=a1 href=# style=position:absolute; top:0; left:0; nav-index:1; nav-down:#b1; nav-right:#a3; nav-left:#a1;
I have a simple animation which simply modify the position of a button: [UIView
I have a simple Android Spinner which I fill with a two column list
I have been trying to create a simple point light in HLSL for a
I have simple project, where I'm using signalR, When page loads, signalR scripts are
I have a simple IRenderable class that has members for position, scaling, and rotation:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.