Hi, for a class, I'm trying to implement a separate-chaining hash table stored in a vector that contains pointers to vectors where the keys will be stored. This is basically what I have:

typedef vector<string> KeyChain;
    vector<KeyChain *> Table;

The problem I'm having is when I want to access the keys in the KeyChain, I don't know how to get to those values, this is what I've tried:

Table[value][index]
    Table[value]->[index]

What is the syntax for accessing the items in a vector that is referenced with a pointer in another vector? Thank you for your help!

kvprajapati commented: First post with code tags. Excellent!!! +5

Welcome squall1986,

Use may use :

(*(Table[index]))[index];

Welcome squall1986,

Use may use :

(*(Table[index]))[index];

Thank you, that works, but I also asked my instructor about it, and he told me that he wanted us to do something along these lines:

vector<string> *Table;
	Table = new vector<string>[size];

So I'll be doing that, but thanks for the help!

So, where is a problem?

vector<string> *Table;
  Table = new vector<string>[2];

  Table[0].push_back("Aaa");
  Table[0].push_back("Bbb");
  Table[0].push_back("Ccc");
    
  Table[1].push_back("Ppp");
  Table[1].push_back("Qqq");
 
cout << "\n" << Table[0][0];
cout << "\n" << Table[0][1];
cout << "\n" << Table[0][2];
cout << "\n" << Table[1][0];
cout << "\n" << Table[1][1];
Table[0][0]="AAAAAA";
....

So, where is a problem?

Umm ... I don't think there is a problem now, it's working fine for me. Are you asking me that because you see one and you want me to look for it ... ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.