我如何添加功能来初始化这个 2dvector 类:-
template <typename T>
class uvector2d
{
public:
uvector2d(size_t xAxis=0, size_t yAxis=0, T const &
t=T()) : xAxis(xAxis), yAxis(yAxis), data(xAxis*yAxis, t)
{}
T & operator()(size_t xNum, size_t yNum)
{return data[xNum*yAxis+yNum];}
T const & operator()(size_t xNum, size_t yNum)
const {return data[xNum*yAxis+yNum];}
private:
size_t xAxis,yAxis;
uvector<T> data;
};
使用统一初始化,如下所示:-
vector<vector<int> > vect{ { 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 } };
我目前正在使用类似的东西:uvector2dvect(3,3); vect(1,1)=10864;