Home » U++ Library support » U++ Core » Why is Vector<double> vdS empty after a call?
Why is Vector<double> vdS empty after a call? [message #10309] |
Sun, 01 July 2007 20:07  |
$mike{is_here}
Messages: 12 Registered: July 2007
|
Promising Member |
|
|
Hi,
Earlier this week I came accross Ultimate: it's a wonderful program in all its facets. My thanks to the developpers
Unfortunately I need a little help with some of its mighty basics. I tried some code, which shall process a list of <double>s, e.g. calculate its sum (yes, I'm from Perl). What amazes me is this: it looks like Vector<double> vdS is truncated after calling sum(). It looks like a single call to vdx. inside sum() is sufficient to do so. I.e. a 2nd call of "s = sum(vdS);" will result in a runtime error.
#include <Core/Core.h>
#include <iostream>
using namespace Upp;
double sum(Vector<double> vdx)
{
double dSum = 0.0;
for(int i = 0; i < vdx.GetCount(); i++) {
dSum += vdx[i];
}
return dSum;
}
CONSOLE_APP_MAIN
{
double s = 0.;
Vector<double> vdS;
int b, a;
vdS.Clear(); vdS.Add(-1); vdS.Add(2); vdS.Add(-5);
b = vdS.GetCount();
s = sum(vdS);
a = vdS.GetCount();
std::cout << "before: " << b << ", after: " << a << std::endl;
// results in "before: 3, after: -1"
}
What am I missing? Can this be a matter of settings (I run MINGW Optimal with XP)? Can it be that double isn't moveable? What is better, i.e. more appropriate to do? And is there a shorthand to initialize vdS?
Thank you all in advance.
Kind regards,
Micha
|
|
|
Goto Forum:
Current Time: Mon May 12 16:08:30 CEST 2025
Total time taken to generate the page: 0.00854 seconds
|