Advertisement
Guest User

Pass-by-Value or Pass-by-Reference for Trivialish Structs

a guest
Feb 12th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. struct A
  2. {
  3.     int x, y, z;
  4. };
  5.  
  6. struct B
  7. {
  8.     A l, u;
  9. };
  10.  
  11. struct C
  12. {
  13.     B t, f;
  14. };
  15.  
  16. // sizeof(A) == 3*sizeof(int)
  17. // sizeof(B) == 6*sizeof(int)
  18. // sizeof(C) == 12*sizeof(int)
  19.  
  20. // foo() does not copy a. Should b be passed by value or by reference?
  21. void foo(A a);
  22. void foo(A const& a);
  23.  
  24. // bar() does not copy b. Should b be passed by value or by reference?
  25. void bar(A a);
  26. void bar(A const& a);
  27.  
  28. // buzz() does not copy c. Should c be passed by value or by reference?
  29. void buzz(A c);
  30. void buzz(A const& c);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement