Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
$mike{is_here} is currently offline  $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 Smile

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
Re: Why is Vector<double> vdS empty after a call? [message #10311 is a reply to message #10309] Sun, 01 July 2007 20:11 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
http://www.ultimatepp.org/srcdoc$Core$pick_$en-us.html
http://www.ultimatepp.org/srcdoc$Core$PickTypes$en-us.html

double sum(const Vector<double>& vdx)
{


Mirek
Re: Why is Vector<double> vdS empty after a call? [message #10312 is a reply to message #10311] Sun, 01 July 2007 20:15 Go to previous message
$mike{is_here} is currently offline  $mike{is_here}
Messages: 12
Registered: July 2007
Promising Member
Hi Mirek,

Thank you for your prompt reply.

Micha
Previous Topic: bad Italian translation in Core.t
Next Topic: Make TimeStop "Moveable"?
Goto Forum:
  


Current Time: Sun May 05 04:25:34 CEST 2024

Total time taken to generate the page: 0.01894 seconds