Forgive my ignorance if this question is too silly. It kept bothering me that in several solutions, the notation of a vector argument is “vector *A” and in the body of the function, a reference is created as “auto& A_ref = *A” and A would never be used again. I’m wondering why not just use
"vector & A" as the argument to the function right from the start. I tried this way on my computer and it worked.
Thanks
A simple question about notation " vector <int> * A " in solutions
Wuyang
#1
0 Likes
Hey Wuyang,
First of all, thanks for your question, and it is a question many people have asked before. Basically you can take a look at http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Reference_Arguments about why we use this. There is nothing wrong about using reference but it is not a good coding style in my opinion.
Please feel free to ask any question, and we are glad to help!
Tsung-Hsien
0 Likes
Wuyang
#3
Hi Tsung-Hsien,
Thank you for the reply. I got it.
The reference is also very helpful.
-Wuyang
0 Likes