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
    关注

    构造函数不支持可变参数

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料