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*>::iterator 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*>::iterator it = v.begin(); // it._Myptr == 0
v.push_back(5);
vector<int*>::iterator 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 4 3423
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*>::iterator 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*>::iterator it = v.begin(); // it._Myptr == 0 v.push_back(5);
This compiles?
vector<int*>::iterator 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
In article <ds**********@volcano1.grnet.gr>,
Chameleon <ch******@hotmail.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.
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*>::iterator 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*>::iterator it = v.begin(); // it._Myptr == 0 v.push_back(5);
This compiles?
sorry, vector<int> v; vector<int*>::iterator 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*>::iterator it = v.begin();
it = v.insert(it, 5);
it++;
it = v.insert(it, 5);
-------------------------------------
Chameleon wrote: vector<int*> v; vector<int*>::iterator 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*>::iterator 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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,...
| |