View Single Post
  #2 (permalink)  
Old February 23rd, 2004, 08:21 PM
nikolai nikolai is offline
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts

Okay, so that sounds like it's a homework assignment. I'd suggest talking to your professor/teacher/teacher's aide/tutor about homework-specific problems, as many schools, classes, and teachers have restrictions on where you can get help for your assignments.

That said:

you don't ever store a vector anywhere! You *create* a vector in your constructor, but don't assign it to anything, so when you're constructor finishes... *poof*! It's gone.

Also, you explicitly create a vector<int>. That doesn't sound like a generic vector to me... you need to create a vector of the same data type your genVector contains.

I would assume that the reason you're creating a genVector is to be able to use arbitrary integer indexes, whereas std::vector is a zero-based index container. That means that your primary goal in creating this vector is to intercept and translate generic indexes to zero-based indexes.

That's really what you should be doing in your constructor and operator[] -- converting between the generic index and the "real" one. After all, it's still std::vector that's storing everything.

If you're still having problems, please let us know (if you're allowed to, that is). I don't want to give you too much information because you really won't learn anything unless you figure it out for yourself. I know it's challenging, but once the light goes on in your head, it'll all seem easy because of your new level of understanding. If one of us just gave you the answer(s), you would just turn in our work and not really understand the "why" or "how" of the assignment.

Finally, I should ask: where is writeVector() defined?

One more thing! For the love of all things decent, [b]use spacing between tokens[b]!!!

    int i;
    for (i=-10;i<=25;i++)
would be a lot more readable as:

    int i;
    for (i = -10; i <= 25; i++)
        tempVector[i] = i;

Take care,

Reply With Quote