fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class foo
  5. {
  6. public:
  7. foo() {}
  8. foo(const foo &f)
  9. {
  10. std::cout<< "огромный объкт, очень долго копируется" << std::endl
  11. << "loading 0....." << std::endl
  12. << "loading 10....." << std::endl
  13. << "loading 20....." << std::endl
  14. << "loading 40....." << std::endl
  15. << "loading 80....." << std::endl
  16. << "loading 100....." << std::endl
  17. ;
  18. }
  19. };
  20.  
  21. void bar(foo f)
  22. {
  23. std::cout<< "закончили" << std::endl;
  24. }
  25.  
  26. void baz(foo &f)
  27. {
  28. std::cout<< "закончили" << std::endl;
  29. }
  30.  
  31. int main() {
  32.  
  33. foo f;
  34.  
  35. std::cout<< "передаём в функцию объект по значению" << std::endl;
  36. bar(f);
  37. std::cout<< "передаём объект по ссылке" << std::endl;
  38. baz(f);
  39. // your code goes here
  40. return 0;
  41. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
передаём в функцию объект по значению
огромный объкт, очень долго копируется
loading 0.....
loading 10.....
loading 20.....
loading 40.....
loading 80.....
loading 100.....
закончили
передаём объект по ссылке
закончили