1

From the example http://www.cplusplus.com/reference/istream/istream/read/ there is the following statement

ifstream is;
...
...

if (is) { // What overloaded operater of **is** object is called here
....
}

What overloaded operator of is object is called ?

Talespin_Kit
  • 20,830
  • 29
  • 89
  • 135
  • possible duplicate of [What is the meaning of "operator bool() const" in C++](http://stackoverflow.com/questions/4600295/what-is-the-meaning-of-operator-bool-const-in-c) – shauryachats Mar 20 '15 at 12:37
  • 1
    @volerag: Only if you already know the answer of the question -- "What overloaded operator is called" -- "`operator bool()`". Thus, the link is related, but the question is not duplicate. – DevSolar Mar 20 '15 at 12:41
  • Well, @DevSolar I think I answered his question *as well as* called it duplicate. Nothing wrong in that, right? – shauryachats Mar 20 '15 at 12:45

2 Answers2

6

Since C++11, there is a conversion operator to bool:

explicit operator bool() const;

Before that, there was a conversion operator to void*:

operator void*() const;

the latter evaluates to true for any non-null pointer and false otherwise.

juanchopanza
  • 223,364
  • 34
  • 402
  • 480
  • And it's worth noting, that if you are writing code where you can't use `operator bool()`, you should read up on the safe bool idiom. – Bill Lynch Mar 20 '15 at 12:42
2

The bool conversion operator of std::basic_ios.

This is functionally equivalent to:

if ( ! is.fail() )
DevSolar
  • 67,862
  • 21
  • 134
  • 209