home *** CD-ROM | disk | FTP | other *** search
- // ex06005.cpp
- // Reference parameters reduce overhead
- #include <iostream.h>
-
- // ---------- a big structure
- struct bigone {
- int serno;
- char text[1000]; // a lot of chars
- } bo = { 123, "This is a BIG structure"};
-
- // -- two functions that have the structure as a parameter
- void slowfunc(bigone p1); // call by value
- void fastfunc(bigone& p1); // call by reference
-
- main()
- {
- slowfunc(bo); // this will take a while
- fastfunc(bo); // this will be a snap
- }
-
- // ---- a call-by-value function
- void slowfunc(bigone p1)
- {
- cout << '\n' << p1.serno;
- cout << '\n' << p1.text;
- }
-
- // ---- a call by reference function
- void fastfunc(bigone& p1)
- {
- cout << '\n' << p1.serno;
- cout << '\n' << p1.text;
- }