What is the meaning of this & in the front of the array (my function only works with & amp ;, I'm overloading cout <
What is the meaning of this & in the front of the array (my function only works with & amp ;, I'm overloading cout <
The question gives the impression that you are learning in an unstructured way, and this is not usually the case. It is important to understand all the concepts, to know why each thing exists and to use. The question seems to point to this, but the way it originated is disturbing. Trying to do something to see if it works does not help understanding. A quality book is recommended to go step by step.
To understand the basics on the subject has the question already mentioned by C. E. Gesser in comment.
In this context, these symbols are not operators, they are part of the type name. Let's say we did not use them and the language would prefer to have explicit type names by extension, it would be alfo like this: reference matriz
and pointer void
.
Note that this has nothing to do with the function or the operator (which in the background is a function as well. They are being used with their return, but this is about the type of data that every function return must have It's just a type declaration to be returned.
These code are weird, or even wrong. The first syntax does not make any sense. The second is not returning anything, let alone a pointer, does not make sense. That's just what worries you. Random codes have been placed, you can not learn it right (I will not put it right because it is not the focus of the question, but can be seen in the SO , in another question ). Anyway, there is too much wrong there.
The reference exists only in C ++. It indicates that the content there will be a pointer managed in some way. There are guarantees that it will not be null and can not be manipulated it as the pointer allows. More details on What is the difference between pointer and reference? .
void*
is used to indicate that there can come any type there since C is a weak language typed and interprets what is there according to the convenience of the programmer. An example of using void*
can be found in another question. This technique is considered obsolete in C ++.
In general, raw pointers should be avoided as much as you give in C ++. They can be overridden by simple references or by smart pointers ( example usage ).
Read more at: