In general the answer is no. You create new, separate strings.
Pre-C++11, std::string
implementations were allowed to share the underlying character array between several strings, and some compilers did it, but it's no longer the case.
If your strings are so long that you need them to share memory, you could use something like std::shared_ptr<std::string>
.
FYI, a better way to write this constructor would be:
travel(std::string from, std::string to)
: obj_from(std::move(from)), obj_to(std::move(to))
{}
Unlike the one you use, it lets you pass temporary and/or const
strings as parameters, while avoiding unnecessary copies.
travel a("foo", "bar");
const std::string x = "baz";
travel b(x, x);