Advertisement

Dynamic Arrays

Started by September 05, 2000 09:39 PM
7 comments, last by Esap1 24 years, 3 months ago
I have a list of Face''s. Though I dont know the size that the list will be as it changes more than once a frame. Its in a Render class, that keeps a List of Faces. You can then add faces. Is there any way to do it without using Linked List''s? Thanks a lot.
Use the standard template library (STL)
either a vector - an array you can initialize to a size x if you try to add beyond the boundaries it will create another array x+y in length.
or a List which is just a double linked list which you know about already.
Advertisement
Could you please show me some code on the first way you mentioned, Ive never used it, thanks for the help,
        #include <vector>#include "face.h" // has class Faceusing namespace std;int main (){  vector<Face> faceVec (10); // 10 faces  faceVec[4].DrawMe (); // calls DrawMe function of 5th Face}        

I still maintain that the best way to learn STL is to get a book. You can try starting with the Microsoft documention (which I believe is really the HP reference documention), but you'd be in trouble. Search the web for STL resources, or go to the Barnes & Noble, bring your Starbucks (tm) Tall Caffeine-o-Chino, and sit down with a notepad in the computer reference section.

BTW, Anonymous's post is incorrect: trying to access an element outside of initialized space will throw an exception, not grow the vector.

ABTW, vector may not be what you want. You might want a map or list. But you'd have to tell us more about your design.

Edited by - Stoffel on September 6, 2000 2:51:46 AM
I didn''t say try to access beyond the array that definitely will not work. What I said was "if you try to add beyond the boundaries it will create another array x+y in length".
You just use the template methods to insert data.
from the programming reference
[2] Memory will be reallocated automatically if more than capacity() - size() elements are inserted into the vector. Reallocation does not change size(), nor does it change the values of any elements of the vector. It does, however, increase capacity(), and it invalidates [5] any iterators that point into the vector.

and some decent references though I do agree a book is better =)
http://www.sgi.com/Technology/STL/
http://hammer.prohosting.com/~yotam/stl/stl.html
Also, check out www.bruceeckel.com he has some good free ebooks!
Sorry, AP: misread your post. Mea culpa.
Advertisement
Can any one give me a link or explain Templates. I think it would be easier to learn STL after I learn Templates
My C++ book doesnt explain them, any help?
I suggest you check out the MSDN. It explains just about everything about VC++ (and VB and Windows and...). I found the info about templates here. You can find info about the STL there too, but you can also find it at The STL programmers guide.

Hope this helps!

Dormeur
Wout "Dormeur" NeirynckThe Delta Quadrant Development Page

This topic is closed to new replies.

Advertisement