What will happen when you attempt to compile and run the following code?

Last Updated on May 22, 2022 by Admin 2

What will happen when you attempt to compile and run the following code?

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
class A 
{
  int a;
public:
    A (int a):a (a) 
    { 
    }
int getA () const 
 {
    return a;
 }
void setA (int a)
 {
   this->a = a;
 }
 bool operator < (const A & b) const
 {
    return a < b.a;
 }         //LINE I
};
struct Compare
{
   bool operator () (const A a)
    {
      return (a.getA () < 6);
    }
};
int 
main()
{
  int mynumbers[] = { 3, 9, 0, 2, 1, 4, 5, 6, 6, 9, 8, 2 };      
  set < A > d (mynumbers, mynumbers + 12);
  int cout = count_if(d.begin(), d.end(), Compare()); //LINE II
  cout << count << endl;
  return 0;
}
  • the program outputs 4
  • the program outputs 6
  • the program outputs 2
  • the exception will be thrown at LINE I
  • compilation error in LINE II
  • the program outputs 1
  • compilation error in LINE I
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments