Ampersand Sign

Hi...
I'm new in C++ programming...

Actually, I want to ask so many things,
but, firstly, I want to ask about & sign...

I have some code:

const BaActivityDeferment& BaActivityDeferment::operator=(
const BaActivityDeferment& rhs)
{
if (this != &rhs)
{
IPFESuper::operator=(rhs);
itsRealDeferment = rhs.itsRealDeferment;
itsShadowDeferment = rhs.itsShadowDeferment;
}
return (*this);
}


What I want to ask is:
What is & sign in const BaActivityDeferment& BaActivityDeferment ?
closed account (zb0S216C)
The ampersand is used in two ways:

1) To reveal the address of the first byte of the right-hand side operand.
2) To reference another object that is of the same type.

Here's an example:

1
2
3
4
5
6
7
8
9
// Address:
std::cout << "Address: 0x" << &Variable << std::endl;

// Reference to a variable:
int A( 10 );
int &B( A );
std::cout << B << std::endl;

// B now refers to A. Any changes made to B affect A. 

Wazzak
Last edited on
Your example is incorrect
int B = A; will make a copy
int &B = A; is an alias
closed account (zb0S216C)
Oops. I'll correct it now.

Wazzak
Topic archived. No new replies allowed.