Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Examples

Example 1: Operators. The streaming operator<< and operator>> for objects of some class type X are perhaps the most compelling examples of functions that are clearly part of the interface of the class X, but which are always nonmember functions (this is of necessity, because the left-hand argument is a stream, not an X). The same argument applies to other nonmember operators on X objects. Make sure that your operators appear in the same namespace as the class on which they operate. When you have the option, prefer making operators and all other functions nonmember nonfriends (see Item 44).

Example 2: Other functions. If the author of X supplies named helper functions that take X objects, they should be supplied in the same namespace, otherwise calling code that uses X objects will not be able to use the named functions without explicit qualification or a using statement.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint