<<<Index>>>

Returning *this


  • Problem: how to allow left-to-right function call chain? For example,


    String s1;
    String s2;
    String s3;

    s1.append( s2 ).append( s3 );

  • Solution: use *this:

    String& String::append( String& other )
    {
        // ...
        return *this; // "return myself"
    }
  • String::append( ) returns a reference to the object it was called on, so calls now can be chained.

<<<Index>>>