C++ Institute C++ Certified Professional Programmer CPP Question # 24 Topic 3 Discussion

C++ Institute C++ Certified Professional Programmer CPP Question # 24 Topic 3 Discussion

CPP Exam Topic 3 Question 24 Discussion:
Question #: 24
Topic #: 3

Which method added to class B at the marked spot will allow the code below to compile? Choose all possible solutions.

#include

#include

#include <algorithm>

using namespace std;

class B { int val;

public:

B(int v):val(v){}

int getV() const {return val;}

/* Insert Code Here */

};

ostream & operator <<(ostream & out, const B & v) { out<

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};

vector v1(t, t+10);

sort(v1.begin(), v1.end(), greater());

for_each(v1.begin(), v1.end(), Out(cout));cout<

return 0;

}


A.

bool operator < (const B & v) const { return val


B.

bool operator > (const B & v) const { return val


C.

bool operator > (const B & v) const { return val>v.val;}


D.

bool operator == (const B & v) const { return val==v.val;}


E.

operator int () const { return val; }


Get Premium CPP Questions

Contribute your Thoughts:


Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.