Advertisement
Guest User

Maker Function Initialization

a guest
Mar 5th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. class Bar
  4. {
  5. public:
  6.   // Conster & Dester
  7.   Bar() { printf("Bar %x is constructed\n", this); }
  8.   ~Bar() { printf("Bar %x is destructed\n", this); }
  9.  
  10.   //Copier
  11.   Bar(const Bar& bar)
  12.   {
  13.     printf("Bar is copied (copy constructor is called): "
  14.        "%x -> %x\n", &bar, this);
  15.   }
  16.   const Bar& operator=(const Bar& rhs)
  17.   {
  18.     printf("Bar is assigned (operator= is called)\n");
  19.     return rhs;
  20.   }
  21. };
  22.  
  23. Bar makeBar_val()
  24. {
  25.   printf("makeBar_val called\n");
  26.   return Bar();
  27. }
  28.  
  29. int main()
  30. {
  31.   printf("Before makeBar_val is called\n");
  32.   Bar bar(makeBar_val());
  33.   printf("After makeBar_val is called, got %x\n", &bar);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement