fork download
  1. #include <iostream>
  2. #include <string>
  3. using std::cout; using std::endl;
  4. struct pizza
  5. {
  6. std::string mypizza;
  7. pizza(const pizza& src): mypizza(src.mypizza)
  8. {
  9. cout << "copy constructor " << this << "<-" << &src << endl;
  10. }
  11. pizza(const pizza&& src) : mypizza(std::move(src.mypizza))
  12. {
  13. cout << "move constructor " << this << "<-" << &src << endl;
  14. }
  15. pizza(std::string makeof) : mypizza(makeof)
  16. {
  17. cout << "My constructor: " << this << " my pizza: " << mypizza << endl;
  18. }
  19. void customize(std::string style)
  20. {
  21. mypizza += ' ' + style;
  22. cout << "custom pizza: " << mypizza << endl;
  23. }
  24. };
  25. pizza customizepizza(pizza opizza, std::string color)
  26. {
  27. opizza.customize(color);
  28. return opizza;
  29. }
  30. int main()
  31. {
  32. pizza pizza_o = customizepizza(pizza("neapolitan style"), "with olives");
  33. cout << "my pizza " << pizza_o.mypizza << endl;
  34. return 0;
  35. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
My constructor: 0x7fff7c936900 my pizza: neapolitan style
custom pizza: neapolitan style with olives
move constructor 0x7fff7c9368c0<-0x7fff7c936900
my pizza neapolitan style with olives