@Geo
Minimalna implementacija 2D matrice u C++-u bez vector-a i veselih macro-a.
Kod:
//Mat2D.h
#ifndef MAT2D_H
#define MAT2D_H
template<typename T>
class Mat2D
{
private:
int width;
int height;
T* data;
public:
Mat2D(int height, int width)
{
this.width = width;
this.height = height;
this.data = new T[width*height];
}
~Mat2D()
{
delete[] data;
}
T& operator()(int x, int y)
{
return data[x*width+y];
}
};
#endif
//main.cpp
int main(int argc, char const *argv[])
{
Mat2D<int> mat(5,10);
mat(0,0) = 42;
int var = mat(4,8);
}