Last active
June 9, 2016 15:35
-
-
Save dolohow/af63ebe84d25e59f2131 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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