Last Updated on May 22, 2022 by Admin 3
What will happen when you attempt to compile and run the following code?
#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[] = {8, 9, 7, 6, 4, 1 }; deque <Pocket> d1 (mynumbers, mynumbers + 6); sort (d1.begin(), d1.end()); d1.push_back(3); //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; }
- runtime error at LINE I
- the program outputs
3,
- compilation error in LINE I
- runtime error at LINE II
- compilation error in LINE II
- the program outputs
3, 4,
- the program outputs
4,