473,938 Members | 12,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dereferencing (pointer to) iterator

Suppose we have a vector:
vector<intvec(1 0);

We can declare a iterator this way:
vector<int>::it erator vecItor;

and then dereference it like this:
for (vecItor = vec.begin(); vecItor != vec.end(); vecItor++)
{
cout << *vecItor << endl;
}

But how can we dereference the iterator if we declare it this way:
vector<int>::it erator* vecItor;

(I need to declare the iterator the second way since I'm declaring it
under a managed C++ class.)

Thanks!

Jun 22 '07
12 4571
<xg****@gmail.c omwrote in message
news:11******** *************@c 77g2000hse.goog legroups.com...
> ... (*vecItor)++

and, REALLY, why do you need this nonsense?

You are right. It should be (*vecItor)++ or ++*vecItor. I need to
declare a iterator this way because in a managed C++ class, the
compiler doesn't allow me to declare like this: vector<int>::it erator
vecItor;

Thank you for your help guys!
"Managed" C++ doesn't allow you to:
std::vector<int >::iterator vecItor;
??? I would chuck that piece of garbage so far out the window it would
leave orbit.
Jun 24 '07 #11
On 2007-06-24 09:11, Jim Langston wrote:
<xg****@gmail.c omwrote in message
news:11******** *************@c 77g2000hse.goog legroups.com...
>> ... (*vecItor)++

and, REALLY, why do you need this nonsense?

You are right. It should be (*vecItor)++ or ++*vecItor. I need to
declare a iterator this way because in a managed C++ class, the
compiler doesn't allow me to declare like this: vector<int>::it erator
vecItor;

Thank you for your help guys!

"Managed" C++ doesn't allow you to:
std::vector<int >::iterator vecItor;
??? I would chuck that piece of garbage so far out the window it would
leave orbit.
It would, but as soon as you start playing with the classes from the
..Net framework (and why use C++/CLR if you don't?) you'll be using
managed classes and they usually don't play well on the stack, so
there'll be lots of List<intl = gcnew List<int>(); all over the place.

--
Erik Wikström
Jun 24 '07 #12
On Jun 22, 11:55 pm, "xgn...@gmail.c om" <xgn...@gmail.c omwrote:
Suppose we have a vector:
vector<intvec(1 0);
We can declare a iterator this way:
vector<int>::it erator vecItor;
Modulo using a typedef, that's the only way to declare an
iterator.
and then dereference it like this:
for (vecItor = vec.begin(); vecItor != vec.end(); vecItor++)
{
cout << *vecItor << endl;
}
But how can we dereference the iterator if we declare it this way:
vector<int>::it erator* vecItor;
That doesn't declare an iterator. It declares a pointer to an
iterator. Given that iterators have value semantics in C++, and
generally are designed to have short and restricted livetimes
(since various modifications to the underlying container can
invalidate them), it's hard to see where this would be
appropriate. Do you really want to have to write things like:

std::vector< int >::iterator* i
= new std::vector< int >::iterator( vec.begin() ) ;
while ( *i != vec.end() ) {
// ...
delete i ;
(I need to declare the iterator the second way since I'm declaring it
under a managed C++ class.)
Ask in a group about managed C++. I'm not familiar with it, but
I don't think that they would have C++ in the name if it didn't
support value types.

--
James Kanze (Gabi Software) email: ja*********@gma il.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Jun 24 '07 #13

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

Similar topics

11
3058
by: Vivi Orunitia | last post by:
Hi all, I tried looking this up in the sgi docs but it didn't provide any concrete answer to what I'm looking for. Basically, is there any difference between using ::iterator for a container vs using ::pointer? I did a quick experiment and replaced all the ::iterator in my code with ::pointer and it seems to work the same. What I'm think is on the surface they're the same but perhaps there're some subtle differences beneath the...
10
1922
by: fabio de francesco | last post by:
Hi what do you think of the following? Why are we permitted to do that? And why the C++ Library doesn't stop someone willing to perfom that assignement (*a = 20)? #include <iostream> using std::cout;
51
3231
by: BigMan | last post by:
Does the C++ standard define what should happen in case of NULL pointer dereferencing. If not, does it say that it is illegal? Where, if so, does it say it?
2
9102
by: Matthias Kaeppler | last post by:
Hello, I was wondering, does dereferencing past-the-end iterators yield undefined behavior? Especially, is the result of calling an STL algorithm on an empty range undefined? For example (pseudocode): begin = find(...);
4
16177
by: Pushkar Pradhan | last post by:
I have some functions which take as i/p a buffer (it can be float, char, or 16 bit, int etc.). The result is another o/p buffer, its type is also flexible (it could be a float, char etc.). I try to pass both as "void *buf" so that it can accept any data type. But since I access the buffer and try to assign its elements to another I get compile errors (I have pasted at the end). Now my question is how can I pass the i/p and o/p buffers...
28
2465
by: Martin Jørgensen | last post by:
Hi, I have a "funny" question, which I think is pretty "healthy" to examine... This program is being investigated: - - - - - - - #include <iostream> using namespace std; #define DAYS 7
9
3216
by: Cyron | last post by:
Hello friends, Recently I have begun exploring the features that the STL map collection provides. While learning how it worked, I encountered a result that confused me. Up until now, I had always been under the impression that if I had a pointer variable, p which contained the member "first", I could access this member variable either by: (*p).first OR p->first . That is, in general I thought p->x was just shorthand for (*p).x ?
4
5246
by: Pritam | last post by:
line 7: error: dereferencing pointer to incomplete type 1. #include<stdio.h> 2. #include<sys/stat.h> 3. #include<stdlib.h> 4. void execname() { 5. struct task_struct *my; 6. my = find_task_by_id(getpid()); 7. printf("%s",my->comm); error: dereferencing pointer to incomplete type
20
3247
by: prashant.khade1623 | last post by:
I am not getting the exact idea. Can you please explain me with an example. Thanks
0
11521
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11104
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...
1
11285
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10653
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9854
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...
1
8216
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6072
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...
2
4444
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3498
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.