C++ destruction of temporary object in an expression

前端 未结 4 1487
孤街浪徒
孤街浪徒 2020-12-06 03:44

Given the following code:

#include 

struct implicit_t
{
    implicit_t(int x) :
        x_m(x)
    {
        std::cout << \"ctor\" <         


        
4条回答
  •  醉酒成梦
    2020-12-06 04:10

    f(42) constructs an unnamed implicit_t implicitly. It lives for the duration of it's containing scope, just as any auto variable would. Naturally, the d'tor gets called on return 0; of main().

提交回复
热议问题