#include <iostream>
using namespace std;
class test
{
public:
test(int a,...);
~test();
void setdata();
void showdata();
int **data;
int *N; //存储每个参量的值
int n; //统计参量的个数
};
test::test(int a,...)
{
int *p=&a;
n=0;
while (*p!=0)
{
n++;
p++;
}
data=new int *[n];
N=new int[n];
p=&a;
int i=0;
while(*p!=0)
{
data[i]=new int[*p];
N[i]=*p;
p++;
i++;
}
}
test::~test()
{
for (int i=0;i<n;i++)
{
delete[] data[i];
}
delete[] data;
delete[] N;
}
void test::setdata()
{
int k=0;
for (int i=0;i<n;i++)
{
for (int j=0;j<N[i];j++)
{
data[i][j]=k++;
}
}
}
void test::showdata()
{
for (int i=0;i<n;i++)
{
for (int j=0;j<N[i];j++)
{
cout<<data[i][j]<<" ";
}
cout<<endl;
}
}
int main()
{
test x(3,4,5,10,6,7,8,0); //最后一个一定是0,以表示参量结束。要是参数中间有零就不好办了。
x.setdata();
x.showdata();
system("pause");
return 0;
}