Which sentence is correct about the code below?
#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; }
/* Insert Code Here */
};
struct add10 { void operator()(A & a) { a.setA(a.getA() + 10); } };
int main() {
int t[] = { 10, 5, 9, 6, 2, 4, 7, 8, 3, 1 };
vector v1(t, t + 10);
for_each(v1.begin(), v1.end(), add10());
vector::iterator it = find(v1.begin(), v1.end(), A(7));
cout << it?>getA() << endl;
return 0;
}
Suggested Answer: B
Get Premium CPP Questions
as Interactive Web-Based Practice Test or PDF
Real Exam Format
Detailed Explanations
Instant Access
Get Your Practice Test
4 comments · newest first
MA
Marlon
3 days ago
I feel like the program might compile but could produce unexpected results if the comparison isn't set up correctly.
LE
Leana
8 days ago
I practiced a similar question where we had to implement comparison operators for a class. I think option D sounds right.
MA
Maira
13 days ago
I'm not entirely sure, but I think if the `operator !=` is not defined, it might lead to compilation issues.
AL
Alba
18 days ago
I remember that we discussed how the `find` function requires the `!=` operator to work properly with custom classes.