当前位置: 动力学知识库 > 问答 > 编程问答 >

Vector_push back not populating the vector (c++)

问题描述:

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.

网友答案:

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..
网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: