How can i add functionality to initialize this 2dvector class:-
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;
};
using uniform initialization as shown below:-
vector<vector<int> > vect{ { 1, 2, 3 },
{ 4, 5, 6 },
{ 7, 8, 9 } };
i am current using something like: uvector2dvect(3,3); vect(1,1)=10864;
Aucun commentaire:
Enregistrer un commentaire