Advertisement
apl-mhd

OOP Constructor Destructor

May 13th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. /*
  2.  *
  3.  *
  4.  * Friend functions are actually not class member function.
  5.  * Friend functions are made to give private access to non-class functions.
  6.  * You can declare a global function as friend,
  7.  * or a member function of other class as friend.
  8.  *
  9.  *
  10.  *
  11.  *
  12.  *
  13.  * */
  14. #include <iostream>
  15. #include <cstdio>
  16.  
  17. using namespace std;
  18.  
  19.  
  20. class diy{
  21.    
  22.    
  23.    
  24.     public:
  25.         string name;
  26.         int id;
  27.    
  28.      diy(string x){
  29.        
  30.         name = x;
  31.          
  32.         }
  33.     diy(){
  34.        
  35.         cout<<"amar sonar bangla\n";
  36.         }
  37.        
  38.     ~diy(){
  39.        
  40.         cout<<"destriction\n";
  41.         }
  42.        
  43. };
  44.  
  45. int main(int argc, char **argv)
  46. {
  47.         diy objct1("Orin");
  48.         diy objct2("Orko");
  49.         diy objct3("Apel");
  50.         diy objct4("Sabi");
  51.        
  52.         diy();
  53.        
  54.         cout<<objct1.name<<" ";
  55.         cout<<objct2.name<<" ";
  56.         cout<<objct3.name<<" ";
  57.         cout<<objct4.name<<" ";
  58.         //objct2.name;
  59.         //objct3.name;
  60.        
  61.    
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement