Skip to content

Instantly share code, notes, and snippets.

@dolohow
Last active June 9, 2016 15:35
Show Gist options
  • Save dolohow/af63ebe84d25e59f2131 to your computer and use it in GitHub Desktop.
Save dolohow/af63ebe84d25e59f2131 to your computer and use it in GitHub Desktop.
#include<iostream>
template <typename T>
class CMatrix{
public:
T* matrix;
int x, y;
CMatrix(int _x, int _y) :x{_x}, y{_y}
{
matrix = new T[x*y];
}
~CMatrix()
{
delete[] matrix;
}
CMatrix(const CMatrix& a) :x{a.x}, y{a.y}
{
matrix = new T[a.x*a.y];
for (int i=0; i<a.x*a.y; i++) {
matrix[i] = a.matrix[i];
}
}
CMatrix& operator=(const CMatrix& a) {
T* p = new T[a.x*a.y];
for (int i=0; i<a.x*a.y; i++) {
p[i] = a.matrix[i];
}
x = a.x;
y = a.y;
delete[] matrix;
this->matrix = p;
return *this;
}
};
int main()
{
CMatrix<int> a(3,4);
CMatrix<int> b(a);
CMatrix<int> c = b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment