Pass by reference

Hi,

I am a bit confused about passing by reference. I understand that when you pass by reference into a function, you are able to modify that object you are passing in. Then in the prototype of the function you would have something like,
int CDummy::isitme (CDummy& param)

So in this example,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;

class CDummy {
  public:
    int isitme (CDummy& param);
};

int CDummy::isitme (CDummy& param)
{
  if (&param == this) return true;
  else return false;
}

int main () {
  CDummy a;
  CDummy* b = &a;
  if ( b->isitme(a) )
    cout << "yes, &a is b";
  return 0;
}


In the main function, object a is passed by reference into the isitme function. But since it says int CDummy::isitme (CDummy& param), shouldn't param already have the address? Why do you need to reference it again by doing &param? Is CDummy& param in the parameter of isitme function just indicating that its parameter is passed in as reference? just like when you declare a pointer * just indicates that its a pointer and it's not actually dereferencing it?

Then in another example
1
2
Catalog myCatalog;
	Catalog& myCatalogRef = myCatalog;


when you declare like that, what is it doing? what does myCaltalogRef have at this point and how is it difference from a pointer?

Thanks for the help!!
You don't need to pass it an address. You pass it a normal object and it takes a reference to the object. That is the point.
Topic archived. No new replies allowed.