In what order do C++ objects passed as arguments to constructors of other objects go out of scope? -


When I compile the following code with G ++, then the object of class A can not be deleted When the object of class C is created, and the BRT_A reference is not broken when used by the Constructor of the object of the class:

  #include & lt; Iostream & gt; Straight A {A (int aa) {a = aa; } ~ A () {std :: cout & lt; & Lt; "A Out" & lt; & Lt; Std :: endl; } Int a; }; Structure B {B (Constant A & A): ref_a (A) {} ~ B () {std :: cout & lt; & Lt; "B Out" & lt; & Lt; Std :: endl; } Consta and A. Ref_a; }; Straight C {C (Const B & B) {c = b.ref_a.a + 1; } Int c; }; Int main (zero) {cc (b (a (1)); Std :: cout & lt; & Lt; CC & LT; & Lt; Std :: endl; }  

However, is this C ++ language guaranteed? Here, floating objects exit the realm, when the instructions are completed. Here are some of the things that you can do to get rid of them.

Here, floating objects exit the scope, That is, after the creator of C comes back again

And yes, this is a guarantee of the C ++ standard.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -