Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 30th, 2004, 5:32 AM   #1
Dia_Byte
Programmer
 
Join Date: Nov 2004
Location: Bierut - Lebanon
Posts: 34
Rep Power: 0 Dia_Byte is on a distinguished road
hi

i'm reading the book : "Teach yourself C++ in 21 days"

and i heard about vectors , but the book doesnot have any explanation about vectors

may any one here please give me a link or a little tutorial about vectors ,

just to get the idea B)

thanks in advance
__________________
<removed by Administrator>
Dia_Byte is offline   Reply With Quote
Old Dec 30th, 2004, 9:46 AM   #2
Tama
Programmer
 
Join Date: Dec 2004
Posts: 35
Rep Power: 0 Tama is on a distinguished road
http://www.cppreference.com/cppvector.html
Tama is offline   Reply With Quote
Old Dec 30th, 2004, 8:28 PM   #3
kurifu
Expert Programmer
 
kurifu's Avatar
 
Join Date: Jul 2004
Location: Halifax, Nova Scotia (Canada)
Posts: 784
Rep Power: 5 kurifu is on a distinguished road
Send a message via ICQ to kurifu Send a message via MSN to kurifu
You can also get more information by searching for "vector class" in MSDN, or at http://msdn.microsoft.com
__________________
Clifford Matthew Roche &lt;geek@cliffordroche.com&gt;
Web Hosting: http://www.crd-hosting.com
Consulting: http://www.crdev-consulting.com
kurifu is offline   Reply With Quote
Old Dec 31st, 2004, 4:59 AM   #4
Dia_Byte
Programmer
 
Join Date: Nov 2004
Location: Bierut - Lebanon
Posts: 34
Rep Power: 0 Dia_Byte is on a distinguished road
ok thanks for the following links but they did'nt do me any good since i don't know what vectors are in the first place ! :wacko:

these link might be usefull if i know what vectors are first
__________________
<removed by Administrator>
Dia_Byte is offline   Reply With Quote
Old Dec 31st, 2004, 5:30 AM   #5
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
i believe they're like dynamically-sized arrays (i.e. change size automatically to fit your needs).
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Dec 31st, 2004, 7:53 AM   #6
Tama
Programmer
 
Join Date: Dec 2004
Posts: 35
Rep Power: 0 Tama is on a distinguished road
>these link might be usefull if i know what vectors are first
It's basically a dynamic array class. The name vector was used because array is a common class name and vector is a convenient mathematical term. If you wanted, you could write your own (very!) simple vector class like so:
#include <cstdlib>
#include <iostream>

using namespace std;

template <typename T>
class Vector {
public:
 Vector();
 ~Vector();
public:
 const T operator[](size_t sub) const { return data[sub]; }
 T& operator[](size_t sub) { return data[sub]; }
 void push_back(T obj);
 size_t size() const { return data_size; }
private:
 T   *data;
 size_t data_size;
 size_t block_size;
};

template <typename T>
Vector<T>::Vector(): data(0), data_size(0), block_size(0)
{}

template <typename T>
Vector<T>::~Vector()
{
 delete [] data;
}

template <typename T>
void Vector<T>::push_back(T obj)
{
 // Grow if necessary
 if (data_size == block_size) {
  block_size = (block_size == 0) ? 1 : block_size * 2;
  T *new_data = new T[block_size];
  for (size_t i = 0; i < data_size; i++)
   new_data[i] = data[i];
  delete [] data;
  data = new_data;
 }
 // Append
 data[data_size++] = obj;
}

int main()
{
 Vector<int> test;

 for (int i = 0; i < 10; i++)
  test.push_back(i);
 for (size_t i = 0; i < test.size(); i++)
  cout<< test[i] <<' ';
 cout<<endl;
 for (size_t i = 0; i < test.size(); i++)
  ++test[i];
 for (size_t i = 0; i < test.size(); i++)
  cout<< test[i] <<' ';
 cout<<endl;
}
In the end, that's all the standard vector class is. It just has a great many more member functions and helper types for convenience and flexibility. Not to mention that the standard container is written with performance in mind, so you can expect it to be a comparable replacement for an array.
Tama is offline   Reply With Quote
Old Dec 31st, 2004, 9:20 AM   #7
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
that sounds a lot like re-inventing the wheel.

programming term...(already been done)...meaning you're wasting your time (unless you're doing it to learn, then it's all good). good luck.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Dec 31st, 2004, 9:37 AM   #8
Tama
Programmer
 
Join Date: Dec 2004
Posts: 35
Rep Power: 0 Tama is on a distinguished road
>that sounds a lot like re-inventing the wheel.
What does? Writing a toy vector class to help someone understand what it is? Or the standard vector class trying to replace arrays?
Tama is offline   Reply With Quote
Old Jan 6th, 2005, 7:55 AM   #9
Dia_Byte
Programmer
 
Join Date: Nov 2004
Location: Bierut - Lebanon
Posts: 34
Rep Power: 0 Dia_Byte is on a distinguished road
thanks for all the replys

and i'm glad to get these examples

__________________
<removed by Administrator>
Dia_Byte is offline   Reply With Quote
Old Jan 6th, 2005, 8:52 AM   #10
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
[/quote] >that sounds a lot like re-inventing the wheel.
What does? Writing a toy vector class to help someone understand what it is? Or the standard vector class trying to replace arrays?[quote]

sounds a lot like i was drunk.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:32 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC