passing reference into constructor

Mar 26, 2009 at 5:50pm
If I have a class named "whatever" with a string member str, and it has the following constructor:

whatever(std::string & s) : str(s) {}

Does s get copied into str or do both s and str end up refering to the same string?
Last edited on Mar 26, 2009 at 5:53pm
Mar 26, 2009 at 6:18pm
It depends on how you declared str. Is it a reference or not?
If it is a reference, then by definition they refer to the same string.
If it is not, then there are two separate string instances that can be
changed without affecting the other.

Mar 26, 2009 at 6:25pm
Ok, thanks.
Topic archived. No new replies allowed.