What does it mean if there is an ampersand right before the function name? Something like:
int& myFunction(int& a, int& b)

Also my book said something about how it doesn't create a copy of something if you pass it by reference, but what exactly does that mean? I never understood that.

Recommended Answers

All 2 Replies

It means the function returns a integer reference for a return value. In your example prototype the function probably returns a reference to either a or b.

>>an ampersand right before the function name

That's the wrong way to think about it. The ampersand is right after the return-type declaration, in other words, the ampersand is part of the definition of the return-type. In this case, the function returns a reference to an int variable. It also takes its two parameters by reference.

Read this for a deeper explanation of references.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.