struct Range
{
size_t ndim;
size_t stWorkSize[3];
size_t stOffest[3];
inline Range ( size_t work_size )
{
ndim = 1;
stWorkSize [0] = work_size;
stWorkSize [1] = stWorkSize [2] = 0;
stOffest [0] = stOffest [1] = stOffest [2] = 0;
}
inline Range ( size_t work_size[2] )
{
ndim = 2;
stWorkSize [0] = work_size[0];
stWorkSize [1] = work_size[1];
stWorkSize [2] = 0;
stOffest [0] = stOffest [1] = stOffest [2] = 0;
}
inline Range ( size_t work_size[3] )
{
ndim = 3;
stWorkSize [0] = work_size[0];
stWorkSize [1] = work_size[1];
stWorkSize [2] = work_size[2];
stOffest [0] = stOffest [1] = stOffest [2] = 0;
}
} ;
我有一个结构定义如上,建议我如何重载构造函数的维数
编译器给我一个错误Range :: Range(size_t *)不能重载
有什么办法可以这样
最佳答案
方法之一是以下
inline Range ( const size_t ( &work_size )[2] )
{
ndim = 2;
stWorkSize [0] = work_size[0];
stWorkSize [1] = work_size[1];
stWorkSize [2] = 0;
stOffest [0] = stOffest [1] = stOffest [2] = 0;
}
inline Range ( const size_t ( &work_size )[3] )
{
ndim = 3;
stWorkSize [0] = work_size[0];
stWorkSize [1] = work_size[1];
stWorkSize [2] = work_size[2];
stOffest [0] = stOffest [1] = stOffest [2] = 0;
}
或者只是定义一个构造函数
inline Range ( const size_t *work_size, size_t n );