LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-23-2003, 10:43 AM   #1
sabeel
LQ Newbie
 
Registered: Aug 2001
Location: montreal, canada
Distribution: redhat
Posts: 22

Rep: Reputation: 15
Vectors in C++


Hi
I wanted to know how i could implement an Array of vectors (each vector holding a pointer to an object).
can someone point me to some webpages.


thanks in advance
sabeel
 
Old 11-23-2003, 11:52 AM   #2
MartinN
Member
 
Registered: Nov 2003
Location: Ronneby, Sweden
Posts: 555

Rep: Reputation: 30
You probably want to use the vector class from the Standard Template Library (STL). STL has ready-made classes for most types of containers and they are used in a consistent way. A good reference to the STL is here:
http://www.dinkumware.com/refxcpp.html

Exactly what do you want to do? You seem to be a little confused. Do you want a vector where every element is a pointer to an object?

Regards
Martin
 
Old 11-23-2003, 12:00 PM   #3
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
do you already know how to use vectors? if you do, then you can use a vector of vectors or if you know how map works, you can make a map of vectors.

one way is to basically define your vector types using typedef:

Code:
#include <string>
#include <vector>

using namespace std;

typedef vector <string> s_vector;
typedef vector <s_vector> vs_vector;

int main ()
{
     s_vector my_string_vec;
     vs_vector my_vec_of_string_vec;

     //do stuff like pushback strings into my_string_vec and
     //and then pushback string vectors into my_vec_of_string_vec.  yada yada yada
     return 0;
}
basically first typedef a vector of strings (in the example above called s_vector) and then typedef a vector of s_vectors (here called vs_vectors). you can then typdef yourself some string and vector iterators to navigate through the strings and vectors if you want, but both of those containers can be navigated using subscripts.

anyway, i don't know of any online stuff except for maybe this: http://www.research.att.com/~bs/C++.html since i use his book for reference mainly:

http://www.research.att.com/~bs/3rd.html

nice basic examples of the c++ stl containers and a nice look into the specifications of such containers.

Last edited by megaspaz; 11-23-2003 at 12:03 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Vectors in Linux Gins Linux - General 4 08-07-2005 04:53 PM
Push into Vectors inside struct in C++ !! Hady Programming 6 05-14-2004 08:34 AM
Vectors in C++! Hady Programming 1 04-13-2004 08:05 AM
LISP question (lists, vectors and strings) llama_meme Programming 2 10-07-2002 04:38 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration