Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. //matrix constructor
  2. mat::mat(int nrows,int ncols){
  3. this->nrows=nrows;
  4. this->ncols=ncols;
  5. this->dat=new float *[nrows];
  6. for(int i=0;i<nrows;i++){
  7. this->dat[i]=new float[ncols];
  8. for(int j=0;j<ncols;j++){
  9. this->dat[i][j]=-9999;
  10. }
  11. }
  12. }
  13.  
  14. template<typename T>
  15. class mat {
  16. //matrix constructor
  17. mat(int nrows,int ncols) {
  18. this->nrows=nrows;
  19. this->ncols=ncols;
  20. this->dat=new T *[nrows];
  21. // ^
  22. for(int i=0;i<nrows;i++){
  23. this->dat[i]=new T[ncols];
  24. // ^
  25. for(int j=0;j<ncols;j++){
  26. this->dat[i][j]=-9999;
  27. }
  28. }
  29. };
  30.  
  31. template<typename T>
  32. class mat {
  33. //matrix constructor
  34. mat(int nrows_,int ncols_)
  35. : nrows(nrows_) , ncols(ncols_) {
  36. dat.resize(nrows);
  37. for(int i=0;i<nrows;i++) {
  38. dat[i].resize(ncols);
  39. for(int j=0;j<ncols;j++) {
  40. dat[i][j]=-9999;
  41. }
  42. }
  43. }
  44. private:
  45. int nrows;
  46. int ncols;
  47. std::vector<std::vector<T>> dat;
  48. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement