各位高手请为小弟指点下,我用VC++6.0 写程序,就申请了1.2M空间,用该数组坐标访问特定的值是总报:Unhandled exception in newTrack2Program.exe:0xC0000005:Access Violation
程序代码:typedef struct InvertIndex
{
int ID;
struct InvertIndex* next;
}* PinvertIndex;PinvertIndex* invertIndex=new PinvertIndex[300000];//共动态申请1.2M空间int main()
{
if(invertIndex!=NULL)
{
invertIndex[250000]->ID=100;
}
return 0;
}
程序代码:typedef struct InvertIndex
{
int ID;
struct InvertIndex* next;
}* PinvertIndex;PinvertIndex* invertIndex=new PinvertIndex[300000];//共动态申请1.2M空间int main()
{
if(invertIndex!=NULL)
{
invertIndex[250000]->ID=100;
}
return 0;
}
invertIndex[250000]->ID=100;
改成
invertIndex[250000].ID=100;
你只是申请了一大堆invertIndex结构的指针而已,invertIndex[250000]->ID当然会非法访问了。
PinvertIndex invertIndex=new InvertIndex[300000];
这样才对
typedef struct InvertIndex
{
int ID;
struct InvertIndex* next;
}InvertIndex, *PinvertIndex;PinvertIndex invertIndex=new InvertIndex[300000];//¹²¶¯Ì¬ÉêÇë1.2M¿Õ¼äint main()
{
if(invertIndex!=NULL)
{
invertIndex[250000].ID=100;
}
return 0;
}
{
int ID;
struct InvertIndex* next;
}InvertIndex, *PinvertIndex;PinvertIndex invertIndex=new InvertIndex[300000];
int main()
{
if(invertIndex!=NULL)
{
invertIndex[250000].ID=100;
}
return 0;
}
你只是申请了一大堆invertIndex结构的指针而已,invertIndex[250000]->ID当然会非法访问了。
PinvertIndex invertIndex=new InvertIndex[300000];
这样才对对楼上所言既是