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

前端 未结 5 1230
忘了有多久
忘了有多久 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:28

    1. look here: Can a local variable's memory be accessed outside its scope?

    2. It will almost will work, since you have no virtual functions, and you don't acces fields of BasicClass: all methods you call have static binding, and 'this' is never used, so you never actually access "not allocated memory".

提交回复
热议问题