jeudi 25 février 2016

User defined explicit conversion in conditionals in C++11

I define an user-defined conversion operator to bool and use it in a conditional:

struct T {
  explicit operator bool() { return true; }
};

int main() {
   T t;
   return t ? 0 : 1;
}

To my surprise this compiles (on gcc) despite the explicit. Is this allowed by the C++11 standard? I searched the standard but couldn't find it.

Aucun commentaire:

Enregistrer un commentaire