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! 12 4555 xg****@gmail.co m wrote:
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.)
What's wrong with **vecItor?
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"xg****@gmail.c om" <xg****@gmail.c omwrote in
news:11******** **************@ z28g2000prd.goo glegroups.com:
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;
**vecItor.
That's a pointer-to-iterator. So you need to dereference your pointer
part, then dereference the iterator.
On Jun 22, 6:04 pm, Andre Kostur <nntps...@kostu r.netwrote:
"xgn...@gmail.c om" <xgn...@gmail.c omwrote innews:11****** *************** *@z28g2000prd.g ooglegroups.com :
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;
**vecItor.
That's a pointer-to-iterator. So you need to dereference your pointer
part, then dereference the iterator.
Thanks guys. That makes perfect sense. However, when I run this in
Visual Studio,
vector<intvec(1 0);
vector<int>::it erator* vecItor = new vector<int>::it erator();
for (*vecItor = vec.begin(); *vecItor != vec.end(); vecItor++)
{
cout << **vecItor << endl;
}
it caused debug assertion failure: vector iterators incompatible.
So I suspect there is no problem with the grammar. I just need to
search somewhere else to
find a way making VS happy.
<xg****@gmail.c omwrote in message
news:11******** **************@ k79g2000hse.goo glegroups.com.. .
On Jun 22, 6:04 pm, Andre Kostur <nntps...@kostu r.netwrote:
>"xgn...@gmail. com" <xgn...@gmail.c omwrote innews:11***** *************** **@z28g2000prd. googlegroups.co m:
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;
**vecItor.
That's a pointer-to-iterator. So you need to dereference your pointer part, then dereference the iterator.
Thanks guys. That makes perfect sense. However, when I run this in
Visual Studio,
vector<intvec(1 0);
vector<int>::it erator* vecItor = new vector<int>::it erator();
You declared a pointer to an iterator, yet you haven't pointed it to
anything yet. It's pointing to random memory since it's uninitialized. I
do not know if:
vecItor = new( std:vector<int> ::iterator );
is legal or not. It may be, I just don't know (have never tried to new a
template before).
for (*vecItor = vec.begin(); *vecItor != vec.end(); vecItor++)
You are using some memory, which your program probably doesn't own, as an
interator. Also, you are incrementing the pointer with vecItor++, did you
mean *vecItor++ (that is, once you actually have it pointing to some memory
set aside as an interator).
{
cout << **vecItor << endl;
}
it caused debug assertion failure: vector iterators incompatible.
So I suspect there is no problem with the grammar. I just need to
search somewhere else to
find a way making VS happy.
xg****@gmail.co m wrote:
On Jun 22, 6:04 pm, Andre Kostur <nntps...@kostu r.netwrote:
>"xgn...@gmail. com" <xgn...@gmail.c omwrote innews:11***** *************** **@z28g2000prd. googlegroups.co m:
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;
**vecItor.
That's a pointer-to-iterator. So you need to dereference your pointer part, then dereference the iterator.
Thanks guys. That makes perfect sense. However, when I run this in
Visual Studio,
vector<intvec(1 0);
vector<int>::it erator* vecItor = new vector<int>::it erator();
for (*vecItor = vec.begin(); *vecItor != vec.end(); vecItor++)
for ( *vecItor = vec.begin(); *vecItor != vec.end(); ++ *vecItor )
However: I have a very hard time to belive that you have a valid reason to
use an iterator* instead of an iterator here. It looks just insane.
{
cout << **vecItor << endl;
}
it caused debug assertion failure: vector iterators incompatible.
So I suspect there is no problem with the grammar. I just need to
search somewhere else to
find a way making VS happy.
Best
Kai-Uwe Bux
Jim Langston wrote:
<xg****@gmail.c omwrote...
>vector<intvec( 10); vector<int>::i terator* vecItor = new vector<int>::it erator();
You declared a pointer to an iterator, yet you haven't pointed it to
anything yet.
The OP sets the pointer to new'd memory, so that's no problem. The iterator
itself points to nowhere, but gets assigned in the for loop:
*vecItor = vec.begin();
Also ok here.
It's pointing to random memory since it's uninitialized. I
do not know if:
vecItor = new( std:vector<int> ::iterator );
is legal or not. It may be, I just don't know (have never tried to new a
template before).
iterator is a typedef inside a template class, so why shouldn't it be legal?
>for (*vecItor = vec.begin(); *vecItor != vec.end(); vecItor++)
You are using some memory, which your program probably doesn't own, as an
interator.
He owns the memory, since he new'd it.
Also, you are incrementing the pointer with vecItor++, did you
mean *vecItor++ (that is, once you actually have it pointing to some memory
set aside as an interator).
This is the problem. The code increments the pointer, not the iterator. It
should be:
++*vecItor
in the for loop.
--
Thomas http://www.netmeister.org/news/learn2quote.html xg****@gmail.co m wrote:
On Jun 22, 6:04 pm, Andre Kostur <nntps...@kostu r.netwrote:
>"xgn...@gmail. com" <xgn...@gmail.c omwrote innews:11***** *************** **@z28g2000prd. googlegroups.co m:
>>Suppose we have a vector: vector<intvec (10);
>>We can declare a iterator this way: vector<int>:: iterator 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>:: iterator* vecItor;
**vecItor.
That's a pointer-to-iterator. So you need to dereference your pointer part, then dereference the iterator.
Thanks guys. That makes perfect sense. However, when I run this in
Visual Studio,
vector<intvec(1 0);
vector<int>::it erator* vecItor = new vector<int>::it erator();
for (*vecItor = vec.begin(); *vecItor != vec.end(); vecItor++)
... (*vecItor)++
and, REALLY, why do you need this nonsense?
{
cout << **vecItor << endl;
}
it caused debug assertion failure: vector iterators incompatible.
So I suspect there is no problem with the grammar. I just need to
search somewhere else to
find a way making VS happy.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
... (*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! xg****@gmail.co m wrote:
> ... (*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,
By "nonsense" I didn't mean a pointer to the iterator. I meant the
"managed C++".
the
compiler doesn't allow me to declare like this: vector<int>::it erator
vecItor;
Thank you for your help guys!
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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;
|
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?
|
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(...);
|
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...
| |
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
|
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 ?
|
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
|
by: prashant.khade1623 |
last post by:
I am not getting the exact idea.
Can you please explain me with an example.
Thanks
|
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...
|
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...
| |
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...
|
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();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |