What happens in C++ when I pass an object by reference and it goes out of scope?

前端 未结 5 1231
忘了有多久
忘了有多久 2020-12-06 18:08

I think this question is best asked with a small code snippet I just wrote:

#include 

using namespace std;

class BasicClass
{
public:
    B         


        
5条回答
  •  借酒劲吻你
    2020-12-06 18:49

    When you store a reference to an object that has ended its lifetime, accessing it is undefined behavior. So anything can happen, it can work, it can fail, it can crash, and as it appears I like to say it can order a pizza.

提交回复
热议问题