I have found it hard to search for the solution, so as my last resource I'd like to show my problem to you. It basically comes down to that I have an array, a dynamic one. Each index of that array holds a set of coordinates (how many, I do not know). Later in my program I want to use those coordinates. The problem is, I thought I knew how I could access them, but apparantly I can't. I'll show you my code:

//Resize of ways
//Reset of coordinates array because here is a new way
while (startsWith(line, "<nd"))
//Resize of coordinates
//coordinates is set (a multiplicity of 2, even: lon-coordinate; odd: lat-coordinate)
ways[count_ways] = *coordinates;
ways_size[count_ways] = size_coordinates;

In a while loop, adds the value of the coordinates array because coordinates is dynamic.

for (unsigned int i = 0; i < count_ways; i ++)
		if (ways_type[i] == 1)
			for (unsigned int i2 = 0; i2 < ways_size[i]; i2 ++)
				file_dest << "[" << *(&ways[i]+i2) << "]";

			file_dest << ways_name[i];
			file_dest << endl;

I write all the ways to the file, but I only get wrong coordinates (read, only incorrect lon coordinates).

I can't figure out why I point to the wrong variables in the last line.

I also find the outcome of the following test rather strange. I placed the following line of code right under the first block of code I've shown you:

cout << &ways[count] << " " << &(*coordinates) << endl;

It outputs 2 different numbers (but if I remove all &'s, they output the same).

I hope one of you can help me, because after trying many times, I haven't succeeded in doing it myself.



Im not quit sure I understand your question, but one thing I see that you might not realize, is that on line 8 you are setting the element at ways[count_ways] to the first element that the coordinate variable points to.

So if coordinate array was {0, 1, 2, 3} and ways array was {10, 20, 30}

On line 8, for example if count_ways == 1, your ways array would now be {10, 0, 30}

aka the first element in the coordinate array.

Hope this helps.

This article has been dead for over six months. Start a new discussion instead.