C++ Institute CPP Question Answer
What happens when you attempt to compile and run the following code?
#include
#include
#include
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 }; struct Compare { bool operator ()(A & a) { if (a.getA() < 5) return true; return false; } }; int main () { int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5}; set d (t,t+15); int number = count_if(d.begin(), d.end(), Compare()); cout<< number< return 0; } Program outputs:
C++ Institute CPP Summary
- Vendor: C++ Institute
- Product: CPP
- Update on: Jul 25, 2025
- Questions: 228