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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:32:49+00:00 2026-06-03T20:32:49+00:00

I thought I was doing this right but it doesn’t seem to be working.

  • 0

I thought I was doing this right but it doesn’t seem to be working. I’m basically experimenting with a queue and it works fine with one data type but now I’m trying to add multiple(in the end I want to have a int and a list of ints).

Here’s the code:

#include <iostream>
#include <queue>
using namespace std;

int main()
{
    struct product {
      int x;
      int y;
    } ;


   queue<product> q;
   q.push(100, 100);
   q.push(200, 100);
   q.push(300, 100);
   q.push(400, 100);

   cout << "Size of the queue: " << q.size() << endl;

   while (!q.empty()) {
       cout << q.front() << endl;
       q.pop();
   }

}

It works without the struct, but obviously it only accepts one variable for each item in the queue that way. Is there a way to have multiple items?

  • 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-03T20:32:51+00:00Added an answer on June 3, 2026 at 8:32 pm

    I think the type specified for the template type cannot be a local definition. Change to:

    struct product {
      int x;
      int y;
    } ;
    
    int main()
    {
    

    As others have already stated, add a constructor to product that accepts both arguments:

    struct product {
        int x;
        int y;
        product(int a_x, int a_y) : x(a_x), y(a_y) {}
    };
    
    ...
    
    q.push_back(product(100, 100));
    

    You could also overload operator<< for outputting a product:

    std::ostream& operator<<(std::ostream& a_out, const product& a_p)
    {
        a_out << "product(" << a_p.x << ", " << a_p.y << ")";
        return a_out;
    }
    
    while (!q.empty()) {
        cout << q.front() << endl;
        q.pop();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I thought this would be fairly easy, but I'm totally baffled. I want one
I thought this code would work, but the regular expression doesn't ever match the
Although I have my php validation doing this, thought I may as well pop
I don't even know if I am doing this query the right way. There
This should be pretty easy but I'm having a heck of a time doing
So I know as3 doesn't have pointers, but I thought there might be a
There are many examples on the internet of doing this type of thing. But
i am doing a continuously select every 10seconds, so i thought i would do
Another noob regex problem/question. I'm probably doing something silly so I thought I'd exploit
can anyone help, i have problem doing a sort, I thought i had it

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.