What happens if you try to compile and run this program?

Last Updated on May 20, 2022 by Admin 2

What happens if you try to compile and run this program?

#include<deque>
#include<iostream>
#include<algorithm>
using namespace std;
class Pocket
{
  int value;
public:
  Pocket(int value):value(value){}
  int getValue()const
  {
    return value;
  }
  bool operator > (const Pocket & _Right)const
  {
    return value > _Right.value;
  }

};
ostream & operator << (ostream & stream, const Pocket & pocket)
{
  stream << pocket.getValue();
  return stream;
}
void
printer (Pocket i)
{
   cout << i <<", ";
}
int
main()
{
  int mynumbers[] = {3, 9, 0, 2, 1, 4, 5};
  deque<Pocket> d1(mynumbers, mynumbers + 7);
  sort(d1.begin(), d1.end(), greater<Pocket>()); //LINE I
  deque<Pocket> :: iterator it = lower_bound(d1.begin(), d1.end(), 3, greater<Pocket>()); //LINE II
  for_each(it, d1.end(), printer);
  return 0;

}
  • the program outputs 3, 4, 5, 9,
  • runtime error at LINE II
  • the program outputs 3, 2, 1, 0,
  • the program outputs 0, 1, 2, 3,
  • compilation error in LINE I
  • compilation error in LINE II
  • runtime error at LINE I
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments