Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

C/C++ API Documentation | 2025.1

# 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

Copy

    #include &lt;iostream&gt;

    #include &lt;stdhdrs.h&gt;
    #include &lt;strbuf.h&gt;

    void called( StrBuf csb )
    {
        csb &lt;&lt; "zy";

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

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

Executing the preceding code produces the following output:

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

Your search for returned results