2

In C++ books I meet the descriptions about how to overload insertion operators for putting data to std::ostream. But when I studied neoengine sources I met this code:

File &File::operator << ( const char *pszData )
{
    if( m_bBinary )
        do m_pkStream->write( pszData, 1 ); while( *pszData++ );
    else
        *m_pkStream << pszData;

    return( *this );
}

As you can see there is no std::ostream using. And I am not sure it correct or not by standart of C++. Where can I look for any official or serious documents or some C++ books where written that code like shown above is correct? That is to say is it to correct to overload insertion operator for own stream classes? Thanks in advance!

graveman
  • 93
  • 6

1 Answers1

0

You are allowed to overload operators for user defined classes, like File.

Whether it always is a good idea, is a matter of opinion.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
  • But where is some official or literature source where it is described? – graveman Oct 01 '15 at 06:58
  • Are you looking for [The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)? – Bo Persson Oct 01 '15 at 07:06