使用vector :: reserve()访问冲突 [英] Access violation using vector::reserve()

查看:174
本文介绍了使用vector :: reserve()访问冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我不明白我遇到的问题是怎么回事 -


行。储备(3); //访问违规


''lines''是结构的向量(''Line'')。无论我是否使用向量< Line> :: size_type对象代替''3',我都得到相同的结果。


至关重要,''行''此时*不是*为空 - 已分配第一个元素。


我看过的书(例如Josuttis)没有给我任何迹象表明转职后的保留电话应该是非法的 - 是吗?


我是C ++的新手(但不是C,Matlab),我遇到了因为'const'而出现的邋iness错误 - 可能有与它有关吗?


再次,如果人们对这个错误是如何可能的想法我会很感激(发布我的所有代码似乎只是将问题暴露在这一点)。


谢谢 -

最好,

马特

Hello,

I don''t understand how the problem I''m having is even possible--

lines.reserve(3); //Access violation

''lines'' is a vector of structs (''Line''). It doesn''t matter whether I use a vector<Line>::size_type object in place of ''3'', I get the same result.

Crucially, ''lines'' is *not* empty at this point--the first element has been assigned.

The books I''ve looked at (e.g. Josuttis) have given me no indication that a post-assignment call to ''reserve'' should be illegal--is it?

I''m new to C++ (but not C, Matlab), and I have run into errors arising from sloppiness on my part with ''const''--could that have something to do with it?

Again, if people have ideas as to how this error is even possible I would appreciate it (posting all my code seems like it would just cloud the issue at this point).

Thanks--
Best,
Matt

推荐答案



您的程序是否首先通过调用您定义的函数来获取该向量?如果是这样,也许你忘记了该函数的return语句。我之前从错过的退货声明中获得了访问冲突。希望这有帮助。
Hi,
Did your program first get ahold of that vector by calling a function that you defined? If it did, maybe you forgot the return statement on that function. I''ve gotten an access violation before from a missing a return statement. Hope this helps.


不,我认为我的编译器(DevC ++ 4.9.9.2)捕获了所有这些(无论如何,这次都没有发生)。


我或许应该更清楚一点 - 访问违规发生在保留声明的字面上 - 不是之前的一个声明或之后的一个声明。


Best,

Matt
No, I think my compiler (DevC++ 4.9.9.2) catches all of those (in any case, didn''t happen this time).

I should perhaps have been more clear--the access violation happens literally at the point of the reserve statement--not one statement before or one statement after.

Best,
Matt


根据我见过的文档,这不是作业。然而,将它声明为const可能会使reserve()失败。
Based on the docs I''ve seen, it''s not the assignment. Declaring it as const, however, probably would make reserve() fail.


这篇关于使用vector :: reserve()访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆