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);
  d1.push_back(3);
  sort(d1.begin(), d1.end()); //LINE I
  pair<deque<Pocket>::iterator, deque<Pocket>::iterator> result = equal_range(d1.begin(), d1.end(), Pocket(4)); //LINE II
  for_each(result.first, result.second, printer);
  return 0;
}
  • the program outputs 4,
  • runtime error at LINE I
  • the program outputs 3, 4,
  • compilation error in LINE I
  • compilation error in LINE II
  • the program outputs 4, 4,
  • runtime error at LINE II
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments