16 lines
489 B
Plaintext
16 lines
489 B
Plaintext
It is unsafe to have ``++const++`` string reference members as they can be created from a temporary quite easily.
|
|
|
|
----
|
|
struct Foo {
|
|
Foo(const string &Str) : Str(Str) {}
|
|
const string &Str;
|
|
};
|
|
Foo instance("string");
|
|
----
|
|
When the constructor is called, a string temporary is created from ``++const char *++`` and destroyed immediately after. This results in a dangling reference.
|
|
|
|
|
|
This rule applies for both ``++std::string++`` and ``++::string++`` ``++const++`` reference members.
|
|
|
|
|