So my problem is that in my class I have to read the size in the constructor. In the other functions of the class( e.g. insert etc.) the table has to EXIST. However, when I try to access it from the other functions (e.g. insert) the table isn't NULL. And the program crashes. Are there any solutions?
Here is a picture of what I want to create:
Here is the code:
Expand|Select|Wrap|Line Numbers
- #ifndef hashdef
- #define hashdef
- using namespace std;
- class hash
- {
- int i;
- int size;
- class hash *table[ ];
- public:
- hash();
- void insert(int a);
- void deletekey(int key);
- bool search(int a);
- void destroy();
- };
- hash::hash()
- {
- cout<<"Give size:";
- scanf("%d",&size);
- class hash * table[size];
- for(i=0;i<size;i++)
- table[i]=NULL;
- }
- void hash::insert(int a)
- {
- if(a[0]==NULL)
- cout<<"it's null"<<endl;
- }