Rocio Karvis: you'd be extra useful utilising a vector or another stl field, except this should be accomplished utilising an array. void addtoarr(vectorfa7153f7ed1cb6c0fcf2ffb2fac21748& arr, int newitem) { arr.push_back(newitem); } int major() { vectorfa7153f7ed1cb6c0fcf2ffb2fac21748 arr; addtoarr(arr, 2); cout
Jesse Pirieda: A reference parameter has an ampersand (&) before the name of the argument (and after the type). So for an int:void somefunction(int &arg1);or if you're using the STL in a class interface file:void somefunction(std::string &str);It could be argued that reference is part of the type, but syntactically, I believe that it makes things easier to read to put it last. For example, a reference argument of type pointer to vector of floats:void somefunction(std::vector* &array1);...Show more
Marjory Stromme: The function would look like this:void GiveMeAThree(int &i){ i=3;}When you call this function, it sets its first parameter to three. For exa! mple:int j=0;GiveMeAThree(j);At this point, 'j's value would be 3....Show more
Jade Ohno: Here's a quick video with a few examples:http://xoax.net/comp/cpp/console/Lesson18.phpIf you want to know what a reference is, here's some background:http://xoax.net/comp/cpp/console/Lesson17.phphttp://xoax.net/comp/cpp/reference/refsandpointers......Show more
No comments:
Post a Comment