c++--構造関数

1130 ワード

1、      :

~  ()

{



}

   ,    ,      ,     

2、  :          (               new      )



                       ,  ,                

       ,         

 :

string *p ;

{

string *q = new string("hello")

p = q ;

}//          ,            ,          

cout<<*p<<endl ; 

     :hello



                     

 



 1 class node

 2 {

 3     public:

 4 

 5     int a,b;

 6     node()

 7     {

 8        *p = "hello" ;

 9         a = 0 ;

10         b = 0 ;

11     }

12     ~node()

13     {

14         cout<<"this is destruct
" ; 15 //delete p ; 16 } 17 18 }; 19 20 int main() 21 { 22 string *q ; 23 24 { 25 node a ; 26 q = a.p ; 27 } 28 29 cout<<"q is "<<*q<<endl ; 30 31 } :hello delete, 。 3、 : , , , ( , ), , 。 4. : , , */