The following code prints one,two,three. Is that desired and true for all C++ compilers?
class Foo
{
const char* m_name;
public:
Foo(const char
Yes, it is desired.
Foo foo("three") creates a normal object which will be destroyed when the scope ends.
Foo("one") creates a temporary object, which is destroyed at the end of the instruction[1]. Why? Because there is no way you can access it after the instruction has ended.
[1] Deliberate simplification: I should have said sequence point.