Ok. I'm reading "Programming Roleplaying Games with DirectX" and at the beginning of the book, there's a C++ primer. The code on function overloading seems like nonsense to me.
Prototypes/Definitions:
In main:Code:long AddNumbers ( long Num1, long Num2 ); long AddNumbers ( long * NumArray, long NumOfNums ); long AddNumbers ( long Num1, long Num2 ) { return ( Num1 + Num2 ); } long AddNumbers ( long * NumArray, long NumOfNums ) { long Result, i; Result = 0; while ( NumOfNums-- ) Result += NumArray [i]; // Hmm? i was not initialized! return Result; }
Code:long Array [5] = { 10, 20, 30, 40, 50 }; Result = AddNumbers ( 10, 20 ); Result = AddNumbers ( Array, 5 ); // Hmm? Shouldn't it be passing an address?
Is this bad code? Or am I seeing wrong?
Also, how could I fix this to pass the entire array? Would I be passing the address of Array?



LinkBack URL
About LinkBacks


