fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<typename _VType, size_t _Len>
  5. class Obc {
  6. private:
  7. const size_t len = _Len;
  8. _VType m[_Len]; // attention: fixed size used for demo
  9. public:
  10. Obc() {}
  11. Obc(_VType *values) {
  12. for (int i=0; i<_Len; i++)
  13. m[i]=values[i];
  14. }
  15. void show() const {
  16. cout<<"Object with len "<<_Len<<" = [ ";
  17. for (int i=0; i<_Len; i++)
  18. cout << m[i] <<" ";
  19. cout<<"]"<<endl;
  20.  
  21. }
  22. };
  23.  
  24. using _DType = int;
  25.  
  26. int main() {
  27. _DType values[]={ 1,2,3};
  28. Obc<_DType, 2> m;
  29. m.show();
  30. Obc<_DType, 2> mat{values}; // assuming _DType *values point to something
  31. mat.show();
  32. auto othermat = mat;
  33. othermat.show();
  34. return 0;
  35. }
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Object with len 2 = [ 0 0 ]
Object with len 2 = [ 1 2 ]
Object with len 2 = [ 1 2 ]