fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <initializer_list>
  4.  
  5. class Matrix {
  6. public:
  7. Matrix(const std::initializer_list<std::initializer_list<double>>&);
  8. void print(const int, const int) const;
  9. private:
  10. const std::vector<std::vector<double>>::size_type d_row;
  11. const std::vector<double>::size_type d_col;
  12. std::vector<std::vector<double>> d_matrix;
  13. };
  14.  
  15. Matrix::Matrix(const std::initializer_list<std::initializer_list<double>>& list)
  16. : d_row(list.size()), d_col((*list.begin()).size()) {
  17. d_matrix.reserve(d_row);
  18.  
  19. for (const auto& l : list) {
  20. d_matrix.emplace_back(l);
  21. }
  22. }
  23.  
  24. void Matrix::print(const int r, const int c) const {
  25. std::cout << d_matrix[r][c] << std::endl;
  26. }
  27.  
  28. int main() {
  29. Matrix m({ {1, 2, 3},
  30. {3, 4, 2} });
  31.  
  32. m.print(0, 0);
  33. m.print(0, 1);
  34. m.print(0, 2);
  35. m.print(1, 0);
  36. m.print(1, 1);
  37. m.print(1, 2);
  38. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
1
2
3
3
4
2