The reason is
the stack frame pointer is not destroyed
even though destructor function of temporary my_class in second loop is called.
when lifetime of a temporary object is ended, c++ make sure the destructor function is called, not the address of that object is marked as invalid.
【 在 Algoquant 的大作中提到: 】
: 把对象捕获绑定在lambda表达式里,对象已经析构了,在调用lambda时不抛异常,按UB处理,这是大坑啊。
: 我发现对这种情况,只能用 enable_share_from_this 来搞,把对象指针shared_ptr<T>托管到队列或者数组里,异步适时再调用该对象的成员函数。 (我的场景:每个算法对象订阅行情,并在收行情数据后调度器按每个股票快照 调用每个算法对象的onMarketDepth(const MarketDepth& md),这里面就涉及每次调度时,算法对象算法是否还存活)
: #include <iostream>
: ...................
--
修改:mvtec FROM 64.44.118.*
FROM 64.44.118.*