<<< operator= and copy constructor | Index | Increment ++ and decrement -- syntax >>> |
Most classes need =, many need ==, some need >.
Numerical classes gain natural syntax of arithmetic operators.
String classes provide + and += for concatenation, and [ ] for character access.
Lookup structures add operator[ ] taking key types:
// PhoneBook.h class PhoneBook { public: string const& operator[]( string const& key ); //... }; // main.cpp #include <iostream> #include "PhoneBook.h" using namespace std; int main( ) { PhoneBook pb; //... cout << "Bob's number is " << pb[ "Bob" ] << endl; return 0; }
<<< operator= and copy constructor | Index | Increment ++ and decrement -- syntax >>> |