尝试用模板编写一个动态数组,构造函数为传入数组大小后申请一定的内存,并将所有值初始化为0,用char类型测试的时候可以,但int类型在打印时就会报错,请问是什么原因呢
template
myArray:: myArray(int num)
{
//数组大小
size = num;
capacity=cal_capacity(num);
//申请空间
data = (T*) malloc(capacitysizeof(T));
if (data == NULL)
{
throw 1;
abort();
}
pbegin = data;
pend = pbegin + sizeof(T) * (num);
for (T it = pbegin; it != pend; it++)
{
*it = (T) 0;
}
}
template
void myArray:: operator << (T &value)
{
std::cout << value;
}
Critical error detected c0000374
报错信息,你复制发给我看看