为什么不能用指针初始类?高手来看看

来源:百度知道 编辑:UC知道 时间:2024/09/22 08:29:22
void CCreat() //创建新的通讯录。
{

S1 *tmp=new S1();

cin>>tmp->Number>>tmp->Name>>tmp->Price>>tmp->Company;
tmp->next=NULL;
int a=charHash(tmp ->Number);

mark: if(S1[a].next->Number!=NULL)
{
a=intHash(a);
goto mark;
}
else
{
tmp->next=&S1[a];
S1[a].next=tmp;
}

}

void SCreat() //创建新的通讯录。
{

Sell *tmp=new Sell();

cin>>tmp->Time>>tmp->Number>>tmp->Amount>>tmp->Price;
tmp->next=NULL;
int a=charHash(tmp ->Time);

mark: if(Sell[a].next->Time!=NULL)
{
a=intHash(a);
goto mark;
}
else
{
tmp->next=&Sell[a];
Sell[a].next=tmp;
}

}
#include"stdafx.h"
#include"iostream.h"
#include"string.h"

你要先定义它是个类的数组吧
void CCreat()
{
Goods *temp=new Goods();
Goods goods[100];//注意看这里
cout<<"输入编号,名称,价格,公司"<<endl;

cin>>temp->Number;
cin>>temp->Name;
cin>>temp->Price;
cin>>temp->Company;

temp->next=NULL;

int a=temp->charHash(temp->Number);

mark:
if( goods[a].next->Number!=NULL )
{
a=temp->intHash(a);
goto mark;
}

else
{
temp->next=&goods[a];
goods[a].next=temp;
}
}

建议你在main函数中创建类的实例