I cant post code since it is a lot, but basically i have a hash table class, created in hash.cpp and hash.h and then a create the table in the main.cpp using hashtable hash (so the constructor) but i need access to hash in other classes, is there a way that is possible?
I tried your code and it didnt seem to help me out, maybe because it was done over different headers and cpp files?. What I want to do is have my hash table class which i have in the hashtable cpp, then the main.cpp creates the table only, using the constructor. And then I want to have a player class, which will allow a player to access the contents of the table, to print it etc.
I have no code for the player class yet, but all it needs to do is be able to access the hash object that is created in the main.cpp.
If this still doesnt explain what i am meaning, i can try again, sometimes i am terrible at explaining myself, please just let me know :)
EDIT: I apologise, i may have been spelling something wrong, your code may work, i will update. again apologies
If the logic inside your Player class needs to access the contents of the hashtable object, then it needs to know what a hashtable is. As far as header file stuff goes, you would need to make sure your Player class file #includes your hashtable header file.
You would still do the same thing,
1 2 3 4 5 6 7 8 9
#include "hashtable.h" // or whatever
#include "Player.h"
int main()
{
hashtable hash;
Player player;
player.access_contents_of(hash);
}
In Player.h:
1 2 3 4 5 6 7 8 9 10
#ifndef PLAYER_H_
#define PLAYER_H_
#include "hashtable.h"
class Player {
public:
void access_contents_of(hashtable& table);
};
#endif // PLAYER_H_
Dealing with multiple files only adds to the complexity here. You don't actually need to use multiple files. You can focus on getting the logic right, and then break up the files if you wish.