2

screenshot

Hi all

There are have been some mistakes on our uni coursenotes this year and I'm just going over quizzes for revision before exams, the attached pic shows the correct answer for "which cannot be implemented as non-member operator overloading.

Posting on here as may not get answer from uni forum in time. Am I misunderstanding something, or is the answer below wrong?

Thanks :)

jewfro
  • 253
  • 1
  • 5
  • 15
  • 5
    The answer marked correct is, indeed, correct. – chris Nov 01 '13 at 23:25
  • 3
    This suspiciously looks like you're trying to get people here to agree with you so you can show your teacher. Tough luck though - the quiz answer seems correct from first glance. – Benjamin Gruenbaum Nov 01 '13 at 23:25
  • 6
    Why does it "look wrong"? Provide reasoning for your position. (This allows verification and/or rebuttals based on asserted facts.) – user2864740 Nov 01 '13 at 23:26
  • Pray tell, how would this overload be called? –  Nov 01 '13 at 23:29
  • I guess my questions is really, if d wouldn't work as a non-member function, then surely c wouldn't either? I should have asked, can c) work as non-member function? – jewfro Nov 01 '13 at 23:30
  • Definitely not @Benjamin. It's not my current teacher's fault, but he's taken over from someone else and there have been some glaring errors on the notes. Such as describing 2 opposite rotations in AVL trees, but the code for both is the same. Or that you should use polymorphism instead of type_ids to TEST types.... – jewfro Nov 01 '13 at 23:34
  • Ah, I get it. I couldn't see it for looking. Revising for an exam and just tired after having to constantly be on the watch out for errors all through this semester of algorithms and data structures. 9/10 when something has frustrated me because it didn't make sense, it has actually been an error Thanks heaps guys! – jewfro Nov 01 '13 at 23:40
  • why it is upvoted? a homework to do, in addition with incorrect assumption and lack of reasoning – 4pie0 Nov 02 '13 at 00:16

2 Answers2

1

A non-member function operator must consist of two arguments. All the options have two arguments other than the last, so d is the answer. If it were made as a member function or a regular function with a name, it would've compiled.

David G
  • 94,763
  • 41
  • 167
  • 253
1

Binary operators like operator > always needs 2 arguments to work. However, member functions get this which acts as the first argument. Non-members of course do not get this and that's why the signature must accept two parameters.

So "d" is correct for your "multiple-guess" question above.

greatwolf
  • 20,287
  • 13
  • 71
  • 105