我用va_list接受不到 求大神们赐教 代码如下:
class data{
public:
data(){
base= nullptr;
constants= nullptr;
bounds= nullptr;
dim= 0;
}
void initial(int d, ...){
if((d< 1)||(d>8)){
cout<< "Somethings wrong with dim"<< endl;
return;
}
dim= d;
bounds= new int[dim];
va_list arg_ptr;
va_start(arg_ptr, dim);
int total= 1;
for(int i= 0;i< dim;i++){
bounds[i]= va_arg(arg_ptr, int);
cout<< bounds[i]<< endl;
total*= bounds[i];
}
va_end(arg_ptr);
base= new int[total];
constants= new int[dim];
constants[dim-1]= 1;
for(int i= dim-2;i>=0;i--)
constants[i]= bounds[i- 1]*constants[i+ 1];
}
void outArray()const{
}
int getTotal()const{
return constants[0]* bounds[0];
}
~data(){
delete[] base;
delete[] bounds;
delete[] constants;
}
private:
int *base;
int dim;
int *bounds;
int *constants;
};