Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / General Programming / 2D Vector arrays Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
Guest42

May 31, 2005, 12:41 PM

A while ago I made my own vector class, mostly just for the experience, but I figured it should be usable, and it is. But recently my teacher asked if I could make a 2 dimensional array with the vector class, and that's where I ran into a snag. I figured, "A vector of vectors", so I tried:

Vector *v = new Vector(10, 5)

Where the arguments are the number of elements to start out with, and how many spots to expand when there's an overflow. Unfortunately, this doesn't actually work. The school's compiler seems to have a problem with a template object as the argument for, well, a template object. Any suggestions?

 
Betelgeuse

May 31, 2005, 12:45 PM

Try > > instead of >>, since the latter is a single token.

 
Betelgeuse

May 31, 2005, 12:48 PM

Just beware that that overflow condition is expensive... moreso because you have a vector of vectors, and because vectors store by value... So when a row is added, all rows are recreated and copied, which means you have n*m calls to new/delete/copy or somesuch.

As for understanding how 2D arrays work, it's not bad... but just don't ever use it for anything =)

 
This thread contains 3 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.