fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cstddef>
  4.  
  5. const size_t CHONK_SIZE = 1000000;
  6.  
  7. template<typename T>
  8. class chonk
  9. {
  10. public:
  11. chonk() : pc(new T[CHONK_SIZE]) {}
  12.  
  13. chonk(const chonk& rhs)
  14. : pc(new T[CHONK_SIZE])
  15. {
  16. memcpy(pc, rhs.pc, CHONK_SIZE*sizeof(T));
  17. }
  18.  
  19. chonk& operator=(const chonk& rhs)
  20. {
  21. delete[] pc;
  22. pc = new T[CHONK_SIZE];
  23. memcpy(pc, rhs.pc, CHONK_SIZE*sizeof(T));
  24. return *this;
  25. }
  26.  
  27. ~chonk() { delete[] pc; }
  28.  
  29. private:
  30. T* pc;
  31. };
  32.  
  33. int main()
  34. {
  35. chonk<int> ci;
  36. chonk<float> cf;
  37. chonk<float> cg { cf };
  38. }
  39.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty