syacer
syacer

Reputation: 167

istream operator overloading without function body? what does it mean?

__istream_type&
operator>>(bool& __n)
{ return _M_extract(__n); }

__istream_type&
operator>>(short& __n);

__istream_type&
operator>>(unsigned short& __n)
{ return _M_extract(__n); }

__istream_type&
operator>>(int& __n);

The above code snip comes from libstdc++, which is basically a bunch of operator overloading for >>. My question is for short and int types, there are not function bodies. Then what does the function do in these cases? Is there a default routing for those functions that have no function body?

Thanks

Upvotes: 1

Views: 84

Answers (1)

Sam Varshavchik
Sam Varshavchik

Reputation: 118445

This is a just an ordinary class method declaration. Nothing out of the ordinary.

When you write your own classes, you must've done the same thing yourself, many times:

class my_class {

      // ...

      void some_method();
};

and then later defined

void my_class::some_method()
{
      // stuff
}

And this is exactly the same thing, here. If you keep reading the header file, you will see

#include <bits/istream.tcc>

tucked away at the end of it.

And if you peruse the contents of this file, you will discover the definition:

 template<typename _CharT, typename _Traits>
    basic_istream<_CharT, _Traits>&
    basic_istream<_CharT, _Traits>::
    operator>>(short& __n)
    {
          // ...

And that's the class method you're looking for.

Upvotes: 1

Related Questions