Advertisement
Guest User

Untitled

a guest
Sep 6th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class Test
  5. {
  6.     std::string value;
  7.  
  8. public:
  9.     Test(const Test & test): // copy c-tor
  10.         value(test.value)
  11.     {
  12.         std::cout << "Test::Test(Test)";
  13.     }
  14.  
  15.     Test(std::string value): //c-tor from value
  16.         value(value)
  17.     {
  18.         std::cout << "Test::Test(string)";
  19.     }
  20. };
  21.  
  22. Test genTest() // to create temporary
  23. {
  24.     Test test = Test("string");
  25.     return test;
  26. }
  27.  
  28. class Container
  29. {
  30.     Test test;
  31. public:
  32.     Container():
  33.     test(genTest()) // initialize from temporary
  34.     {
  35.     }
  36. };
  37.  
  38. int main()
  39. {
  40.     Container container;
  41.     return 0;
  42. }
  43.  
  44. //Output:
  45. //Test::Test(string)
  46. //Copy constructor is unused
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement