大虾看看这个问题怎么解决呀?????
代码如下,编译运行的时候在newhash=new hashtable*[size]; 的地方出现段异常呀,WHY????
#include<iostream>
#include<string>
using namespace std;
const int DEFAULT_SIZE=50;
class myhash
{
private:
struct bucket
{
char* strname;
bucket* next;
};
struct hashtable
{
bool is_empty;
char* strname;
bucket* next;
};
int size;
hashtable **newhash;
public:
myhash(void);
myhash(int n);
bool put(char* key);
};
myhash::myhash(void)
{
int i;
size=DEFAULT_SIZE;
newhash=new hashtable*[size]; //????
for(i=0;i<size;i++)
{
newhash[i]->is_empty=true;
newhash[i]-> next=NULL;
}
}
myhash::myhash(int n)
{
int i;
size=n;
newhash=new hashtable* [size];
for(i=0;i<size;i++)
{
newhash[i]->is_empty=true;
newhash[i]-> next=NULL;
}
}
bool myhash::put(char* key)
{}
int main(void)
{
myhash a;
}