int main(){
nArray A(2, 3, 4);
}
/******************************/
template
class nArray{
private:
aElem* base;
int dim;
int * bounds;
int * constants;
private:
Status Locate(va_list, int&);
public:
nArray(int, ...);
~nArray(){ if (base) delete[] base; if (bounds) delete[]base; if (constants) delete[]constants; }
Status Value(aElem&, ...);
Status Assign(aElem, ...);
};
template
nArray::nArray(int d, ...) :dim(d), base(nullptr), bounds(nullptr), constants(nullptr){
va_list ap;
va_start(ap, d);
int elemtotal = 1;
bounds = new int[dim];
constants = new int[dim];//运行到这行前,dim=2,貌似没问题,可是一到这行运行完,dim就变成了1323297024,并且有时程序崩溃出错,我实在找不到原因了,希望有前辈能指点下
for (int i = 0; i < dim; i++){
bounds[i] = va_arg(ap, int);
if (bounds[i] < 0) exit(UNDERFLOW);
elemtotal *= bounds[i];
}
va_end(ap);
base = new int[elemtotal];
if (!base) exit(OVERFLOW);
constants[dim - 1] = 1;
for (int i = dim - 2; i >= 0; --i)
constants[i] = constants[i + 1] * bounds[i + 1];
}
大学生,刚开始学,问题可能极低级,请见谅
还有因为没什么人指点,如果哪写的不妥,也都请一并指出来,我好好改正,谢谢啦
数据结构 有关多维数组的问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
悬赏问题
- ¥15 如何在scanpy上做差异基因和通路富集?
- ¥20 关于#硬件工程#的问题,请各位专家解答!
- ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
- ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
- ¥30 截图中的mathematics程序转换成matlab
- ¥15 动力学代码报错,维度不匹配
- ¥15 Power query添加列问题
- ¥50 Kubernetes&Fission&Eleasticsearch
- ¥15 報錯:Person is not mapped,如何解決?
- ¥15 c++头文件不能识别CDialog