473,395 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

STL vector with iterators

Hi there,
i've got a STL list like this:
list<object *> myList;
Now, i want to create a vector with iterators of this list like this:

vector< list<object *>::iterator > myVector

Where's the fault?

thanks for reply,
Jan

Jan 20 '06 #1
5 1466
Ja*********@t-online.de wrote:
Hi there,
i've got a STL list like this:
list<object *> myList;
Now, i want to create a vector with iterators of this list like this:

vector< list<object *>::iterator > myVector

Where's the fault?


That's ok. If you're using it in a template, it won't work. You'll
need this:

vector< typename list<object *>::iterator > myVector

You may also need to worry about const-ness.

vector< typename list<object *>::const_iterator > myVector
Jan 20 '06 #2
Ja*********@t-online.de schrieb:
Hi there,
i've got a STL list like this:
list<object *> myList;
Now, i want to create a vector with iterators of this list like this:

vector< list<object *>::iterator > myVector

Where's the fault?


Where's the code ?

S.
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de
Jan 20 '06 #3
Ja*********@t-online.de said the following on 20/01/2006 12:51:
Hi there,
i've got a STL list like this:
list<object *> myList;
Now, i want to create a vector with iterators of this list like this:

vector< list<object *>::iterator > myVector
Can you try this template class ?

template< typename T > class MyVector
: public std::vector< typename std::list <T *> :: iterator > {
};

Where's the fault?

thanks for reply,
Jan

Jan 20 '06 #4
Ja*********@t-online.de wrote:
Hi there,
i've got a STL list like this:
list<object *> myList;
Now, i want to create a vector with iterators of this list like this:

vector< list<object *>::iterator > myVector

Where's the fault?

thanks for reply,
Jan


I recommend not using raw pointers in your container, and instead use
smart pointers like boost::shared_ptr or smart_ptr
http://code.axter.com/smart_ptr.h
Other pointers:
http://code.axter.com/cow_ptr.h
http://code.axter.com/copy_ptr.h

Are you sure you need the list container in the first place. It's
rarely optimal to use std::list over std::vector/std::deque.
If you're not doing a lot of insertions and deletions in the center of
the container, you should consider just using std::vector in the first
place.
I recommend you do some performance test to see if you really need the
std::list in the first place.

Jan 20 '06 #5

Gianni Mariani wrote:
Ja*********@t-online.de wrote:
Hi there,
i've got a STL list like this:
list<object *> myList;
Now, i want to create a vector with iterators of this list like this:

vector< list<object *>::iterator > myVector

Where's the fault?


That's ok. If you're using it in a template, it won't work. You'll
need this:

vector< typename list<object *>::iterator > myVector

You may also need to worry about const-ness.

vector< typename list<object *>::const_iterator > myVector


When and why you need 'typename' is explained pretty well in Thinking
in C++ V2, which is available for download on the internet.

Jan 20 '06 #6

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

Similar topics

11
by: Richard Thompson | last post by:
I've got a memory overwrite problem, and it looks as if a vector has been moved, even though I haven't inserted or deleted any elements in it. Is this possible? In other words, are there any...
3
by: codefixer | last post by:
Hello, I am trying to understand if ITERATORS are tied to CONTAINERS. I know the difference between 5 different or 6(Trivial, on SGI). But what I fail to understand is how can I declare all 5...
13
by: zaineb | last post by:
Hi, This is a follow-up of sort of this thread:...
23
by: Sanjay Kumar | last post by:
Folks, I am getting back into C++ after a long time and I have this simple question: How do pyou ass a STL container like say a vector or a map (to and from a function) ? function: ...
2
by: ma740988 | last post by:
typedef std::vector < std::complex < double > > complex_vec_type; // option1 int main() { complex_vec_type cc ( 24000 ); complex_vec_type dd ( &cc, &cc ); } versus
9
by: Christian Chrismann | last post by:
Hi, I've a runtime problem with STL vectors. Here is the simplified version of the code: template <class Tclass A { ... private: vector<T*myvector; typename vector<T*>::itarator mIt;
2
by: ernesto | last post by:
Hi: I want to create my own vector class; I want to provide methods like: class Vector { public: void add(const Object* aVal); void remove(const Object* aVal); };
12
by: desktop | last post by:
Why does insert only work when specifying an iterator plus the object to be inserted: std::vector<intt; std::vector<int>::iterator it; it = t.begin(); t.insert(it,33); If I use push_back...
16
by: xyz | last post by:
I have to run the simulation of a trace file around (7gb contains 116million entries)... presently i am using vector iterators to check the conditions in my program..... it is taking 2 days to...
0
by: subramanian100in | last post by:
Suppose I have vector<intc; for (int i = 0; i < 10; ++i) c.push_back(i); vector<int>::iterator it = find(c.begin(), c.end(), 5); If I do, c.insert(c.begin(), 10);
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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,...
0
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,...
0
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...
0
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...

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.