473,809 Members | 2,740 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

iterator problem

All these happen in VC++ NET 2003, if you ask me about the compiler.
it._Myptr is a VC++ specific member of the iterator implementation.
But from this, we extract usefull informations about crash.
----------------------------
vector<int*> v;
vector<int*>::i terator it = v.begin(); // it._Myptr == 0 (what pointer
is this?)
v.insert(it, 5); // works
it++; // it._Myptr == 4
v.insert(it, 5); // crashes
----------------------------
and this.
----------------------------
vector<int*> v;
vector<int*>::i terator it = v.begin(); // it._Myptr == 0
v.push_back(5);
vector<int*>::i terator it = v.begin(); // it._Myptr == 0x00323b40 (the
pointer to first element)
----------------------------
All of these are compiler bugs on iterator implementation, or I miss
something?

Thanks
Feb 4 '06 #1
4 3450
Chameleon wrote:
All these happen in VC++ NET 2003, if you ask me about the compiler.
it._Myptr is a VC++ specific member of the iterator implementation.
But from this, we extract usefull informations about crash.
----------------------------
vector<int*> v;
vector<int*>::i terator it = v.begin(); // it._Myptr == 0 (what
pointer is this?)
The same as v.end(). No bug. You're not going to dereference it.
v.insert(it, 5); // works
That's okay, but invalidates "it".
it++; // it._Myptr == 4
Unfortunately, "it" is invalid.
v.insert(it, 5); // crashes
Yup.
----------------------------
and this.
----------------------------
vector<int*> v;
vector<int*>::i terator it = v.begin(); // it._Myptr == 0
v.push_back(5);
This compiles?
vector<int*>::i terator it = v.begin(); // it._Myptr == 0x00323b40
(the pointer to first element)
----------------------------
All of these are compiler bugs on iterator implementation, or I miss
something?


Ah, not every error is a compiler error!

Cheers, Calum

Feb 4 '06 #2
In article <ds**********@v olcano1.grnet.g r>,
Chameleon <ch******@hotma il.NOSPAM.com> wrote:
All of these are compiler bugs on iterator implementation, or I miss
something?


Until you know enough that you can build your own compiler, go ahead and
assume that the bug is in your code rather than the compiler's code...
Just a thought.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.
Feb 5 '06 #3
Calum Grant wrote:
Chameleon wrote:
All these happen in VC++ NET 2003, if you ask me about the compiler.
it._Myptr is a VC++ specific member of the iterator implementation.
But from this, we extract usefull informations about crash.
----------------------------
vector<int*> v;
vector<int*>::i terator it = v.begin(); // it._Myptr == 0 (what
pointer is this?)


The same as v.end(). No bug. You're not going to dereference it.
v.insert(it, 5); // works


That's okay, but invalidates "it".
it++; // it._Myptr == 4


Unfortunately, "it" is invalid.
v.insert(it, 5); // crashes


Yup.
----------------------------
and this.
----------------------------
vector<int*> v;
vector<int*>::i terator it = v.begin(); // it._Myptr == 0
v.push_back(5);


This compiles?


sorry, vector<int> v;
vector<int*>::i terator it = v.begin(); // it._Myptr == 0x00323b40
(the pointer to first element)
----------------------------
All of these are compiler bugs on iterator implementation, or I miss
something?


Ah, not every error is a compiler error!

of-course!

my solution is this until now:

-------------------------------------
vector<int*> v;
vector<int*>::i terator it = v.begin();
it = v.insert(it, 5);
it++;
it = v.insert(it, 5);
-------------------------------------
Feb 5 '06 #4
Chameleon wrote:
vector<int*> v;
vector<int*>::i terator it = v.begin(); // it._Myptr == 0
v.push_back(5);
This compiles?


sorry, vector<int> v;


Okay, vector<int>. Good.
my solution is this until now:

-------------------------------------
vector<int*> v;
vector<int*>::i terator it = v.begin();
it = v.insert(it, 5);
it++;
it = v.insert(it, 5);
-------------------------------------


Back to vector<int*> now? Well, in any case... line 2 above serves no
purpose. I would change this snippet to:

std::vector<int > v;
v.push_back(5);
v.push_back(5);

See? No need for iterators at all in this case. Maybe you got
confused because you didn't know about push_back? You owe it to
yourself to learn the public interface of important classes like
std::vector. It is only wafer-thin.

Luke

Feb 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
3699
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages mentioned: I characterized one way of looking at languages in this way: a lot of them are either the agglutination of features or they're a crystallization of style. Languages such as APL, Lisp, and Smalltalk are what you might call style...
0
1387
by: CoolPint | last post by:
I am trying to write a generic heapsort (of course as a self-exercise) with Iterator interface: something like blow.... But I got into trouble finding out the Iterator to the Child node. If indexing was used, I could do something like child = hole * 2 + 1; but since only thing the function accepts are random access Iterators, how do I calculate the Iterator to the child node? template <typename Iterator, typename Functor> void...
26
1514
by: Michael Klatt | last post by:
I am trying to write an iterator for a std::set that allows the iterator target to be modified. Here is some relvant code: template <class Set> // Set is an instance of std::set<> class Iterator { public : typedef typename Set::value_type T; typedef typename Set::iterator SetIterator; Iterator(Set& container, const SetIterator& it);
2
2016
by: Lorenzo Castelli | last post by:
This is an old problem of mine. Basically I have an abstract base class which represents a generic iterator over a collection of elements, and various derived classes that implement the traversing on specific data structures. For each iterator I want to be able to specify the four possible const combinations, corresponding to the various void* for pointers, with the possibility to perform conversions from non-const to const just like...
0
2683
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never looked for one on the net (I did browse the boost library though). It doesn't matter right now, anyway. To put it simply, Abstract Iterator is mainly a wrapper class. It helps
21
5727
by: T.A. | last post by:
I understand why it is not safe to inherit from STL containers, but I have found (in SGI STL documentation) that for example bidirectional_iterator class can be used to create your own iterator classes by inheriting from it, ie. class my_bidirectional_iterator : public bidirectional_iterator<double> { ... };
16
2592
by: mailforpr | last post by:
How do I do that? The thing is, the only information I have about the iterator is the iterator itself. No container it is belonging to or anything. Like template<Iteratorvoid totally_isolated(Iterator& it) { //how do I find out if it points to the end node? }
1
6243
by: David Bilsby | last post by:
All Apologies for cross posing this but I am not sure if this is a VC 8 STL bug or simply an invalid use of the iterator. I have a PCI card access class which basically abstracts a third party library from the higher level classes. This low level class is used to allocate locked pages of memory before doing a DMA. The third party library locks memory and returns a pointer to an internal structure, which we can simply cast to a (void...
4
2010
by: mkborregaard | last post by:
Hi, I have the weirdest problem, and I can not see what is going wrong. I have made a 2d container class, and am implementing an iterator for that class. However, the ++ operator is behaving very strange. The implementation looks like this (there is a lot of code, but I have only included it all for consistency. The problem is quite small and local): template<typename T> class Row<T> : public std::vector<T> {}; template<typename...
5
2292
by: Luis Zarrabeitia | last post by:
Hi there. For most use cases I think about, the iterator protocol is more than enough. However, on a few cases, I've needed some ugly hacks. Ex 1: a = iter() # assume you got the iterator from a function and b = iter() # these two are just examples.
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5688
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.