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 6622889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:27:54+00:00 2026-05-25T21:27:54+00:00

I have defined an array of pairs as following: std::pair<int,int> delta[4]; delta[0] = std::make_pair(0,1);

  • 0

I have defined an array of pairs as following:

std::pair<int,int> delta[4];
delta[0] = std::make_pair(0,1);
delta[1] = std::make_pair(1,1);
delta[2] = std::make_pair(1,0);
delta[3] = std::make_pair(1,-1);

but when I try to access the elements like:

delta[2].first

I get an error as following :

binary '[' : 'std::pair<_Ty1,_Ty2>' does not define this operator or a conversion to a type acceptable to the predefined operator
error C2228: left of '.first' must have class/struct/union

Here is the function where I access it:

#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

int who_won(std::pair<int,int> &delta,std::vector<std::vector<int>> &grid);

int main(int argc, char** argv)
{
    std::fstream input;
    input.open("E:\\in.txt",std::ios_base::in);
    std::string line;
    char ch;
    std::vector<std::vector<int>> grid;
    std::vector<int> row;
    while(input.get(ch))
    {
        if(ch == '\n')
        {
            grid.push_back(row);
            row.clear();
        }
        else if(ch != ',')
        {
            row.push_back(std::atoi(&ch));
        }
    }

    if(row.size()>0)
        grid.push_back(row);
    row.clear();

    std::pair<int,int> delta[4];
    delta[0] = std::make_pair(0,1);
    delta[1] = std::make_pair(1,1);
    delta[2] = std::make_pair(1,0);
    int l = grid.size();
    for( int i =0; i < l; ++i)
    {
        //auto & v = *i;
        for( int j = 0; j < l; ++j)
            std::cout<<grid[i][j]<<" ";
        std::cout<<"\n";
    }

    int winner = who_won(*delta,grid);
    if( winner == 0)
    {
        if( std::find(grid.front().begin(),grid.front().end(),0) == grid.front().end())
            std::cout<<"draw";
        else
            std::cout<<"play";
    }
    else if( winner == 1)
        std::cout<<"1";
    else if( winner == 2)
        std::cout<<"2";


    return 0;
}

int who_won(std::pair<int,int> delta[],std::vector<std::vector<int>> &grid)
{
    int l = grid.size(),connect;
    for(int px = 0; px < l; ++px)
    {
        for(int py = 0; py < l; ++py)
        {

            for(int i = 0;i < 4;++i)
            {
                connect = 0;
                for(int j = 1;j < 4;++j)
                {
                    if( grid[px + delta[i].first*j][py + delta[i].second*j] != grid[px][py])
                        break;
                    else
                        connect++;
                }
                if(connect == 4)
                    return grid[px][py];
            }
        }
    }
    return -1;
}

Where am I going wrong ?

  • 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-05-25T21:27:55+00:00Added an answer on May 25, 2026 at 9:27 pm

    You method signature only specifies a reference to a single std::pair instance. You would probably want your signature to look something like the following if you want to pass an array of std::pair.

    int who_won(std::pair<int,int> delta[],std::vector<std::vector<int>> &grid)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

An array is defined of assumed elements like I have array like String[] strArray
I have defined the following Array Dim myArray(10,5) as Long and would like to
Lets say I have a array defined in Groovy like this def int[] a
I have defined two dimensional array using following definition typedef std::vector<std::vector<short> > table_t; Can
how to delete all elements of a std::tr1::array? For example I have defined the
I have array defined like this : ArrayList<String> items = new ArrayList<String>(); I have
I have an array defined like this, result = [true,false,false,false] In my code I
Coming from a perl background, I have always defined a 2D array using int[][]
I have defined an array that can hold 10 elements. I have add 3
I have an array defined: int [,] ary; // ... int nArea = ary.Length;

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.