ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

c – 无法访问对向量中的值

2019-09-02 08:06:46  阅读:204  来源: 互联网

标签:std-pair c vector


我有一个对矢量作为对象内的字段.所述对象具有一种方法,其中我需要访问向量中的对中的值.我使用迭代器指向我想要访问的向量中的位置.以下是包含向量的代码片段:

在头文件中:

vector<pair<double, double> > points;
vector<pair<double, double> >::iterator headingTo;

在构造函数中:

 points.push_back(make_pair(1700.00, 3300.00));//Plus 20 or so other values
 headingTo = points.begin();

在方法中:

double x = headingTo->first - positionX;
double y = headingTo->second - positionY;

但是,当我运行此代码时,没有创建y.当我使用断点来查看变量时,它根本没有在Visual Studio中显示.但是,如果我交换线条,y是可访问的,而x则不是.有任何想法吗?

编辑:
我发现了以下作品:

double headingToX = headingTo->first; 
headingToX -= positionX;
double headingToY = headingTo->second;
headingToY-= positionY;

解决方法:

检查您是否正在调试程序的优化版本 – 在这种情况下,如果编译器可以确定它不需要生成所需的程序输出,则可以自由地删除变量.

但是,即使您使用的是非优化版本,如果您根本不使用该变量,也会发生这种行为.在this bug report on the Express version of VC++ 2010中,您将看到Microsoft代表发表的以下评论(强调添加):

Is this issue only occuring on variable that you have not used in any
way other than assigning a value? The presence of the variable in the
.pdb via inspection with a hex-editor, or seeing a corresponding “mov”
instruction in the dissassembly does not guarantee that the compiler
did not do some level of optimzation that prevents the debugger from
inspecting the variable (the compiler always does small optimizations
even in a debug build). The debugger can only guarantee access to a
variable will be provided by the compiler if the variable is used in
the application for another purpose other than being assigned a value.

If you have a repro where the variable is being used (other than being
assigned a value) and you cannot inspect it in the debugger please let
us know. Otherwise, this is an artifact of compiler optimizations.

从您发布的代码中不清楚您是否稍后使用y的值.

标签:std-pair,c,vector
来源: https://codeday.me/bug/20190902/1789541.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有