I have a weird problem and I just can't find the reason.
I am rather new to c++ so I was hoping, that one of you might find the error.
The Problem:
I have written a class that does a bubblesort on a vector<double>.
The algorithm works just fine. But somehow, a couple of "cout"s alter the output of the vector length. Example ...
This sounds like memory corruption. Can we see the source of the class that does the sorting? The fact that you're using pointers to the vectors scares me. (Not to mention that you have public member variables! eek!)
This constructs a vector of doubles called tvec, takes its address and stores it in the pointer vec, and then destructs tvec. The pointer vec is a dangling pointer, any further access to it is undefined.
There is no reason at all to use pointers in this program, store the vector as-is, not as a pointer.
(or, for the smallest fix, change vec = &tvec; to vec = &avec; )
thanks for your help. The Tip with the pointer was the solution.
I am rather new to C++ and I am used to Java being my mother and taking care of things if you know what I mean ;-)