Compute the sum of all elements of the vector.
int Sum( int & nSum )
int Sum( double & dSum )
int Sum( complex & cxSum )
Returns 0 on success or a non-zero error code on failure.
EX1
void vectorbase_Sum_ex1() { // Sum elements of a vector of type short vector<short> vecS = {1, 2, 3, 4, 5}; int iSum; vecS.Sum(iSum); out_int("iSum = ",iSum); // Result: // iSum = 15 }
EX2
void vectorbase_Sum_ex2() { // Sum elements of a vector of type double vector vecD = {1.1, 2.1, 3.1, 4.1, 5.1} double dSum; vecD.Sum(dSum); out_double("dSum = ",dSum); // Result: // dSum = 15.5 }
EX3
void vectorbase_Sum_ex3() { // Sum elements of a vector of type complex vector<complex> vecC = {1+2i, 3+4i, 5-6i}; complex cSum; vecC.Sum(cSum); out_complex("cSum = ",cSum); // Result: // cSum = 9 + 0 i }
Compute the sum of all elements of the vectorbase object. The argument type must be greater than or equal to the base type of the vectorbase object.
origin.h