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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:05:58+00:00 2026-05-30T00:05:58+00:00

I am trying to add a user-defined plane object to a priority queue: int

  • 0

I am trying to add a user-defined plane object to a priority queue:

int main( ) 

{

 std::string filename;
 cout << "Enter file name >> ";
 getline( cin, filename );

 ifstream fin;
 fin.open( filename.c_str( ) );
 if( fin.fail( ) )
 {
      cout << "Unable to open the input file" << endl;
      exit(1);

 }
priority_queue<Plane*,vector<Plane*>,greater<Plane*> > pq;
Plane * p1;
 while(fin)
 {
      fin.get( );
        fin >> *p1;
        pq.push(*p1);

 }
 Plane p;
 int size=pq.size();
 for(int i=0;i<3;i++)
 {
     p=pq.top();
     cout<<i<<" "<<p;
     pq.pop();
 }
}

The plane-class:

#include "plane.h"

Plane::Plane( )
{
flightNum = "Not set";
numOfPassengers = -1;
fuel = -1;
}

ostream& operator << ( ostream& os, const Plane& p )
{
os << "Flight Number: " << p.flightNum
   << "\nNumber of Passengers " << p.numOfPassengers
   << "\nRemaining fuel: " << p.fuel;

return os;
}
bool Plane::operator>(  const Plane& p2) const
{
 if(this->fuel>p2.getFuel())
 {
     return true;
  }
 else
 {
     return false;
 }
}
ifstream& operator >> ( ifstream& fin, Plane& p )
{
  fin>>p.flightNum;
  fin>>p.numOfPassengers;
  fin>>p.fuel;
}

The error I am receiving is:

 In function ‘int main()’:

welcome.cc:127: error: no matching function for call to ‘std::priority_queue<Plane*,              
std::vector<Plane*, std::allocator<Plane*> >, std::greater<Plane*> >::push(Plane&)’
/usr/lib/gcc/i686-redhat-   
linux/4.4.6/../../../../include/c++/4.4.6/bits/stl_queue.h:509: note: candidates are:   
void std::priority_queue<_Tp, _Sequence, _Compare>::push(const typename  _Sequence::value_type&) [with _Tp = Plane*, _Sequence = std::vector<Plane*, std::allocator<Plane*> >, _Compare = std::greater<Plane*>]
welcome.cc:151: error: no match for ‘operator=’ in ‘p = pq.std::priority_queue<_Tp, _Sequence, _Compare>::top [with _Tp = Plane*, _Sequence = std::vector<Plane*, std::allocator<Plane*> >, _Compare = std::greater<Plane*>]()’

The requirement of the program is that it needs to add the plane object to the priority queue. The priority is the fuel of the plane.

  • 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-30T00:05:59+00:00Added an answer on May 30, 2026 at 12:05 am

    The first error is because you didn’t include cstdlib header file

    Second when you use a user defined class with a priority queue, how is the container supposed to compare your new type in this case “The plane class” ? Hence you should overload the less than (< ) operator.

    You have overloaded the greater than operator ( > )

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying to add some ability to my project to allow user-defined properties
I am trying to add user-defined aggregates to a SQL Server 2008 database whose
I'm trying to add a class (.active) to a text field once the user
I am trying to create an iPhone application where the user can add entries.
I am trying to build a shopping cart site. When a user click add
add unique Elements to List of User defined class (i.e. List ) public class
Hey, I am trying to return a user defined class from a web method.
Hello I’m a trying to create a feature where an user an add an
I'm trying to download the 'User Defined' variables using the google analytics API. The
I'm trying to calculate how closely an item matches a user's defined preferences. The

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.