-2

Why don't we need to specify the return type when overloading a casting operator like bool/string

operator bool()

but we need to define the return type when overloading a comparison operator (!, >, <)

bool& operator ! ()

Why don't we define it as bool operator bool() instead.

Ak-Mo
  • 389
  • 1
  • 4
  • 18

1 Answers1

0

bool is the return type in operator bool().

Barry
  • 286,269
  • 29
  • 621
  • 977
  • I know, but why don't we need to specify the return value here (same for string) – Ak-Mo Dec 22 '18 at 17:06
  • 1
    @Ak-Mo I don't understand what that question means. – Barry Dec 22 '18 at 17:06
  • Edited the question, in short, I'm trying to understand why we don't define it as: `bool operator bool()` – Ak-Mo Dec 22 '18 at 17:11
  • @Ak-Mo Because that's redundant at best and suggests that you could put different types in the two slots at worst. – Barry Dec 22 '18 at 17:12