As I see in some code having something like "ClassName&".
For example:

// this demo
// check if a parameter passed to a member function is the object itself
#include <iostream>
using namespace std;

class CDummy {
	public : 
		int isitme ([b]CDummy[u]&[/u] param[/b]);		
};

int CDummy :: isitme ([b]CDummy[u]&[/u] param[/b]) {
	if (&param == this) return true;
	else return false;
}

void main () {
	CDummy a;
	[b]CDummy*[/b] b = &a;
	if (b -> [i]isitme(a)[/i]) {
		cout << "yes, &a is b";
	}
}

I know "ClassName*" is used to declare a pointer to a class instantiation. But what is "ClassName&"? What is the difference between the "&" reference operator and this "&" in "ClassName&"?

Sorry if it is a stupid question!
Thank for any help.

Attachments
// this demo
// check if a parameter passed to a member function is the object itself
#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;
}

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

The notation ClassName& means reference to ClassName.
For example,

int no=10;
  int& ref=no;

In above code snippet, variable ref and no refer to the same int value.

If you want to get a pointer to the object denoted by a ref, you can write:

int *ptr=&ref;    // address of (&) operator.

Edited 6 Years Ago by __avd: n/a

Comments
Thanks!

Also, see this post and for an article with lots of examples, see this.

(sorry adatapost, I was already in process when you posted)

Comments
Thanks. After reading your example, I remember that my problem related to "passing by ref".
You are always helpful

* is the dereference operator
* gets the value

& is the opposite. it gets the address instead of the value.

Really, you aught to know this. Its like pointers 101.

This question has already been answered. Start a new discussion instead.