rvalue is not destroyed

Nov 16, 2016 at 9:22am
Hi guys,

I though that after function call all rvalue parameters send to function will be destroyed. I'm completely messed up with this example. Can someone help me with it? Maybe some links where it explained.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Test
{
public:
    Test(const char* name)
        : ptr(nullptr)
    {
        ptr = name;
    }

    ~Test()
    {
        printf("%s\n", ptr);
        system("PAUSE");
    }

    const char* ptr;
};

int main()
{
    Test t("Hello");
}  

Last edited on Nov 16, 2016 at 9:23am
Nov 16, 2016 at 10:15am
I figured it out on my own. The answer is that basic types has static lifetime, in other words they are never destroyed.
Nov 16, 2016 at 10:23am
only string literals have static storage duration, see http://en.cppreference.com/w/cpp/language/string_literal
Topic archived. No new replies allowed.