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

  • SEARCH
  • Home
  • 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 8033443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:41:56+00:00 2026-06-05T01:41:56+00:00

I have tried to write this code: #include <iostream> #include <map> using namespace std;

  • 0

I have tried to write this code:

#include <iostream>
#include <map>

using namespace std;

typedef struct 
{
    int x;
    int y;
}position;

int main(int argc, char** argv)
{
    map<position, string> global_map;
    position pos;
    pos.x=5;
    pos.y=10;
    global_map[pos]="home";
    return 0;
}

In truth this isn’t the original code, but a version simplified of it (I’ am trying to make a tetris game with OpenGL).
Anyway the problem is a syntax error on the line where I say: “global_map[pos]=”home”;”.
I don’t get the reason of the error, and I post it here for who needs more details:

invalid operands to binary expression (' position const' and 'position const')
  • 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-05T01:41:58+00:00Added an answer on June 5, 2026 at 1:41 am

    The requirement for associative containers, which std::map is one of, is that there must be an ordering between the elements used as keys. By default, this is std::less which simply calls operator <. So all you need to do to use your struct as a key in a std::map is implement operator < for it.

    struct position
    {
        int x;
        int y;
    };
    
    bool operator <( position const& left, position const& right )
    {
        return left.x < right.x || ( left.x == right.x && left.y < right.y );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have a look at this code: #include<stdio.h> #include <unistd.h> int main() { int pipefd[2],n;
The following code works fine #include <functional> using namespace std; using namespace std::placeholders; class
I want to write a file_handle class like this #include <stdio.h> #include <iostream> #include
I have tried to write a program where i want to access class in
I have tried to write my first Boost program from information on the Boost
How can you write a VB.NET Windows Forms Application via CodeDom? I have tried
Have tried to find solutions for this and can't really come up with anything.
I have tried a lot to get this done but I dont know how
I have tried finding an answer to this problem and in every post I
I have an std::map , and I would like to define an iterator that

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.