wangshuai199406 2014-10-19 07:20 采纳率: 0%
浏览 2015

c++类中的成员函数和构造函数怎么接受数量不定的参数啊

我用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;
};

  • 写回答

1条回答 默认 最新

  • oyljerry 2015-01-01 14:01
    关注

    构造函数不支持可变参数

    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题