StrBuf::StrBuf( const StrBuf & ) (Copy Constructor)

Construct a copy of a StrBuf.

Virtual?

No

 

Class

StrBuf

 

Arguments

const StrBuf &s

(implied) reference of the StrBuf from which copying occurs

Notes

The StrBuf copy constructor creates a copy of a StrBuf. The StrBuf from which copying occurs must be initialized before calling the copy constructor.

The StrBuf copy constructor initializes the new StrBuf to contain a zero-length null buffer, and sets the contents of the new StrBuf using the contents of the original StrBuf. Any memory allocated for the buffer of the copy is separate from the memory for the buffer of the original StrBuf.

Example

#include <iostream>

#include <stdhdrs.h>
#include <strbuf.h>

void called( StrBuf csb )
{
    csb << "zy";

    cout << "called() csb.Text() returns \"" << csb.Text() << "\"\n";
}

int main( int argc, char **argv )
{
    StrBuf sb;
    sb.Set( "xyz" );
    called( sb );   // copy constructor called
    cout << "main() sb.Text() returns \"" << sb.Text() << "\"\n";
}

Executing the preceding code produces the following output:

called() csb.Text() returns "xyzzy"
main() sb.Text() returns "xyz"