lundi 5 juin 2017

Copy constructor for Vector of Vectors

I've built a hash table using a vector of vectors holding type Entry. From table.h:

private:
int size;
int num_entries;
int max_entries;
vector<vector<Entry> > A;

unsigned int hashkey(unsigned int key) const;

I am supposed to write a copy constructor this is what I have:

Table::Table(Table &t) {
    num_entries = t.num_entries;
    max_entries = t.max_entries;
    size = max_entries * 2;
    A.resize(size);
    for(size_t i = 0; i < t.A.size(); i++) {
        for (size_t j = 0; j < t.A[i].size(); j++) {
            A[i][j] = t.A[i][j];
        }
    }
}

It compiles fine but when I try to actually use the copy constructor I get a bad access code error. I'm not sure how to fix this or what that even means (something wrong with accessing t)? Any help is appreciated.

Aucun commentaire:

Enregistrer un commentaire