home *** CD-ROM | disk | FTP | other *** search
- // ex06006.cpp
- // Reference parameters eliminate pointer notation
- #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 ptrfunc(bigone *p1); // call by pointer
- void reffunc(bigone& p1); // call by reference
-
- main()
- {
- ptrfunc(&bo); // pass the address
- reffunc(bo); // pass the reference
- }
-
- // ---- a pointer function
- void ptrfunc(bigone *p1)
- {
- cout << '\n' << p1->serno; // pointer notation
- cout << '\n' << p1->text;
- }
-
- // ---- a call by reference function
- void reffunc(bigone& p1)
- {
- cout << '\n' << p1.serno; // reference notation
- cout << '\n' << p1.text;
- }