yungman
- 5,741
- 294
Yes, They are passed by reference so it's NOT returning anything.Mark44 said:As I'm sure you know, function whose parameters are passed by reference, either as C++ references or as pointers, can modify its actual parameters, as in the following example. Strictly speaking, the function below doesn't return anything, but when it returns a has been increased by 1 and b has been increased by 2.
That's the sense in which @yungman meant that a function could "return" two values.
C++:void alterTwoVars(int& x, int& y) { x += 1; y += 2; } int main() { int a = 3, b = 5; alterTwoVars(a, b); }
I have been reading the books over, it is still not clear to me why I cannot have two functions with only one template<class T> declaration. My understanding is when you make this declaration, meaning the function that use T data type becomes a "mold" or blue print of a function. Then in the program, compiler will search the function name ( like swapVars or larger) and instantiate the object accordingly. So why can't I define 2 function with T?
Another question I want to clarify, template ONLY work on function, ADT like struct and class, it is NOT for declaring variable type like what I did T a; to declare a is T type that I can make it int, double, string variable in the program.
Thanks