I realize this is probably a dumb question but I couldn't find the answer anywhere... What is the purpose of the '&' symbol in C++ functions? Such as
vec2& operator+(vec2& left, const vec2& right)
{
return left.add(right);
}
I'm following a youtube series that's a little over my head, but I'm doing fine because all the code is there. However that 'and' symbol keeps popping up and I'd really like to know what it is... Does it have something to do with classes?
Here's exactly what I'm watching: https://www.youtube.com/watch?v=-peYVLeK0WU Guy from a channel called "TheChernoProject" making a simple game engine. Also, this is Visual Studio 2013 C++, if that changes anything.
English has two articles: the and a/an. The is used to refer to specific or particular nouns; a/an is used to modify non-specific or non-particular nouns. We call the the definite article and a/an the indefinite article. For example, if I say, "Let's read the book," I mean a specific book.
“The” is typically used in accompaniment with any noun with a specific meaning, or a noun referring to a single thing. The important distinction is between countable and non-countable nouns: if the noun is something that can't be counted or something singular, then use “the”, if it can be counted, then us “a” or “an”.
Articles are used before nouns or noun equivalents and are a type of adjective. The definite article (the) is used before a noun to indicate that the identity of the noun is known to the reader. The indefinite article (a, an) is used before a noun that is general or when its identity is not known.
Use "the" with any noun when the meaning is specific; for example, when the noun names the only one (or one) of a kind. Adam was the first man (the only 'first man'). New York is the largest city in the United States (only one city can be 'the largest'). We live on the earth (the only Earth we know).
"&" can mean several different things, depending on the context.
The example you gave above is the C++ "reference operator":
Need help understanding reference operator(C++) in specific functions
The reference operator is specific to C++. "&" can also be used as the "address of" operator, used in both C and C++:
What are the differences between a pointer variable and a reference variable in C++?
Finally, "&" can also be the bitwise "AND" operator:
http://www.cprogramming.com/tutorial/bitwise_operators.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With