0

I'm not getting any error messages, simply my vector is not populating. Looking at the vector in the watch list, nothing is being copied. Why is this? I've tried two ways. The first

std::vector<Point3D*>   hitpoints;
local_hit_point = sr.local_hit_point; //local_hit_point class Point3D 
hitpoints.push_back(local_hit_point);

The second way I tried to use pointers

std::vector<Point3D*>   hitpoints; 
Point3D* hittingpoint_ptr = new Point3D;
local_hit_point = sr.local_hit_point;
hittingpoint_ptr = &local_hit_point;
hitpoints.push_back(hittingpoint_ptr);

I got vectors in other places in my code which work. Am I really just being daft, but I can't seem to figure out why its not working.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Seb
  • 3,655
  • 3
  • 17
  • 17
  • 2
    How do you know that it is not populating? (source code please) – Vincent Cantin Apr 07 '12 at 12:04
  • 1
    If you only have one, why do you use it? Is it possible that `sr.local_hit_point` is actually an array of Point3D? In that case you would need to loop through them all and add them one by one. –  Apr 07 '12 at 12:04
  • You can use `hitpoints.size()` to see how many elements there are. When storing pointers, are you sure that the pointed-to object stays in place? – Bo Persson Apr 07 '12 at 12:08
  • Vincent. When I debug I have a 'watch list' and I can see that nothing is going into hitpoints. What source code would you like? sr.local_hit_point returns a x,y,z Cartesian coordinate point of a ray hitting a object. The vector is in a 'for' loop, and I want to store the hitpoint at each pass. Bo Persson, how do I test if the pointed to object stays in place? – Seb Apr 07 '12 at 12:17
  • 1
    In you second way: Why are you creatin new point and than equalizing it to another pointer..you will lose that pointer in this case..By the way are sure that your debugger is not mal-functioning.. – Semih Ozmen Apr 07 '12 at 12:19
  • @BoPersson vector nothing to do with its elements values..I mean you can push invalid pointers to a vector of pointers. – Semih Ozmen Apr 07 '12 at 12:24
  • @BoPersson I used hitpoint.size(). Is it possible that the there are just too many values? – Seb Apr 07 '12 at 12:30
  • @SemihOzmen I was trying to create a new point and pointing to the location of another point. Did I do the second way wrong? It still doesn't answer why nothing is being stored in the vector though – Seb Apr 07 '12 at 12:35
  • No your second way has no effect on this behaviour. I just gave it as an additional comment.. – Semih Ozmen Apr 07 '12 at 12:42

2 Answers2

0

My best guess is that you have an issue with you debugger..

First Suggestion;

  • Clear everything in your watchlist because they can change the behaviour of the execution check it again..

Second suggestion;

  • Create a new project and write a simple code like the one above and see whether your vector is populating..If this simple project works, you should provide us more code and details..
Semih Ozmen
  • 571
  • 5
  • 20
0

simply my vector is not populating.

It is populating. However

Looking at the vector in the watch list ... I used hitpoint.size()

Results of function/method calls (size() is a method) are not automatically updated in visual studio watch list (because you haven't told what os/compiler you use I had to assume it is visual studio). I.e. if you enter function call into watch list, it'll calculate results, but will not call function again until you manually refresh it. Instead of function call, add vector itself into watch list.

SigTerm
  • 26,089
  • 6
  • 66
  • 115