VC++6.0小问题
帮我看看这个程序,编译\链接都没错,运行也没错但当我在MAIN()中把HugeInt a(6);成HugeInt a(7);或HugeInt a(8);....只要是大于6,运行时都不成功,请问这是为什么吗啊?
#ifndef _HUGEINT_H
#define _HUGEINT_H
class HugeInt
{
private:
int *data;
int size;
public:
HugeInt(int);
HugeInt(HugeInt &);
~HugeInt(){delete [] data;}
void display();
};
#endif
#include <iostream.h>
#include "HugeInt.h "
#include <string.h>
HugeInt::HugeInt(int s)
{
data=new int(s);
for (int i=0;i <s;i++)
data[i]=0;
size=s;
}
HugeInt::HugeInt(HugeInt &p)
{
data=new int(p.size );
for(int i=0;i <p.size ;i++)
data[i]=p.data[i];
size=p.size ;
}
void HugeInt::display()
{
for(int i=0;i <size;i++)
cout < <data[i];
}
#include "HugeInt.h "
#include <iostream.h>
void main()
{
HugeInt a(6);
a.display();
cout < <endl;
}
帮我看看这个程序,编译\链接都没错,运行也没错但当我在MAIN()中把HugeInt a(6);成HugeInt a(7);或HugeInt a(8);....只要是大于6,运行时都不成功,请问这是为什么吗啊?
[解决办法]
data=new int[s];
[解决办法]
new int(s);?????
change to:
new int[s];
[解决办法]
intArray = new int[num];
intPointer = new int;
[解决办法]
new type(vaule)是分配一个后赋初始数值
new type[num]分配num个type
[解决办法]
data=new int[s];