简体   繁体   中英

Insertion operator overloading for own stream class

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!

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM