At this point I am trying to get data from a std::list or std::vector. I push_back the object from a pointer into the list and go on my merry way, I do this until I get to the point I want (which is working at the moment) but then when I go to my function to iterate through the list and output it I only get the last two objects over and over for the size of the list.

for(list<Lidar>::iterator swathit = Swath.begin(); swathit != Swath.end(); ++swathit)
         (*swathit).print();

it doesn't seem like it should be that hard but something is royally messing up somewhere. If you have any ideas at all throw them out there.

Cameron

The error is not in your for loop, it is perfectly OK.
You need to post some more code.

Will do

while (infile >> numberholder)
	{

		pLidar = new Lidar;
		(*pLidar).SetX(numberholder);
		double xtest = (*pLidar).GetX();

		infile >> numberholder;
		(*pLidar).SetY(numberholder);
		double ytest = (*pLidar).GetY();

		infile >> numberholder;
		(*pLidar).SetZ(numberholder);
		double ztest = (*pLidar).GetZ();

		if(run >=2)
		{
			infile >> numberholder;
			(*pLidar).SetGround1(numberholder);
		}

		if(run >=3)
		{
			infile >> numberholder;
			(*pLidar).SetGround2(numberholder);
		}

		if(run >=4)
		{
			infile >> numberholder;
			(*pLidar).SetGround3(numberholder);
		}

		if(min_x > (*pLidar).GetX())
		{
			min_x = (*pLidar).GetX();
		}
		if(min_y > (*pLidar).GetY())
		{
			min_y = (*pLidar).GetY();
		}
		if(max_x < (*pLidar).GetX())
		{
			max_x = (*pLidar).GetX();
		}
		if(max_y < (*pLidar).GetY())
		{
			max_y = (*pLidar).GetY();
		}

		Swath.push_back(*pLidar);
		cout << oyeholder++ << endl;
		delete pLidar;
		pLidar = 0;

		double thediff = Swath.back().GetX() - min_x;
		if(thediff >= cellsize)
		{
			findpoints(Swath, temp, max_x, max_y, min_x, min_y, tolerance, cellsize, separator_sign, date, swathnum, run);
			oyeholder = 0;
		}
	}

That is the code that reads in the data from the file and pushes it to the back of the list, and the function call to the findpoints function.

It has to happen somewhere in there because I have put that loop in three different places checking if the list got corrupted somewhere between the loading and the function call. But it is officially some where in the loading part. If needed i can post the Class code but I will spare you guys from that for now because it is just extra pasting and reading.

Cameron

I might have a better shot of making sense of it if you attached full source. I'm just not connecting the dots. (Besides, I am curious about little things like new ing and delete ing within this loop as opposed to (re)using a single temporary.)

I figured out my problem after digging around in a book for a while. I wasn't using an explicit copy constructor, therefore my code did some really weird stuff. Now that I have put together a full copy ctor all is well.

Oh, and the newing and deleting that I am doing in there was kind of a test idea that i thought would maybe help. And it made it so it would put in two different values instead of just one repeatedly...Yeah I know, confusing right?

Cameron

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.