1

I'm sure there's a better way to do this.

I'm trying to create a class HashTable that is given a size at instantiation, so it can't be given a size at design time, so I can't use an array as my internal representation of the table, as far as I know.

So here's what I'm trying to do:

#include <vector>
#include <iostream>
#include "Nodes.h"

using namespace std;

template <class T>
class HashTable{

protected:
    vector<* TableNode<T>> myTable;
    //other protected methods go here

public:
    HashTable(int size){
        myTable = vector<* TableNode<T>>(size,NULL);
    }

//The rest of the class
};

From what I've seen, vector is the best data structure to use here, because it will let me give it a size in the constructor, and lets me use myTable[index] style notation to access its contents. However, VS2010 doesn't like my use of vector<* TableNode<T>> and I can't say I blame it. So, how do I create an array or vector or whatever of pointers to TableNode<T> elements?

0

2 Answers 2

2

Move the asterisk around:

vector<TableNode<T>*> myTable;

myTable = vector<TableNode<T>*>(size,NULL);
Sign up to request clarification or add additional context in comments.

Comments

0
vector<TableNode<T>*> myTable;
myTable = vector<TableNode<T>*>(size,NULL);

FTFY.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.