Skip to main content
Update contents
Source Link
JimmyHu
  • 7.5k
  • 2
  • 11
  • 48

Use std::copy instead

You don't need to implement CopyData. You can use std::copy to copy array data like std::copy(right.data_, right.data_ + right.size_, data_); and std::copy(data_, data_ + (new_size > size_ ? size_ : new_size), ptr);

Avoid using namespace std;

std namespace is a quite large namespace. This behavior completely obviates the benefits of namespaces because it brings all its names into the global namespace. Please check What's the problem with "using namespace std;"? and make a habit of using the (very short) namespace prefix std::.

Avoid flush the output buffer unnecessarily

You use std::endl quite a lot. There are two purposes for std::endl: 1)print a newline, 2) flush the underlying output buffer. If you just want a new line, use '\n' instead.

Avoid using namespace std;

std namespace is a quite large namespace. This behavior completely obviates the benefits of namespaces because it brings all its names into the global namespace. Please check What's the problem with "using namespace std;"? and make a habit of using the (very short) namespace prefix std::.

Avoid flush the output buffer unnecessarily

You use std::endl quite a lot. There are two purposes for std::endl: 1)print a newline, 2) flush the underlying output buffer. If you just want a new line, use '\n' instead.

Use std::copy instead

You don't need to implement CopyData. You can use std::copy to copy array data like std::copy(right.data_, right.data_ + right.size_, data_); and std::copy(data_, data_ + (new_size > size_ ? size_ : new_size), ptr);

Avoid using namespace std;

std namespace is a quite large namespace. This behavior completely obviates the benefits of namespaces because it brings all its names into the global namespace. Please check What's the problem with "using namespace std;"? and make a habit of using the (very short) namespace prefix std::.

Avoid flush the output buffer unnecessarily

You use std::endl quite a lot. There are two purposes for std::endl: 1)print a newline, 2) flush the underlying output buffer. If you just want a new line, use '\n' instead.

Source Link
JimmyHu
  • 7.5k
  • 2
  • 11
  • 48

Avoid using namespace std;

std namespace is a quite large namespace. This behavior completely obviates the benefits of namespaces because it brings all its names into the global namespace. Please check What's the problem with "using namespace std;"? and make a habit of using the (very short) namespace prefix std::.

Avoid flush the output buffer unnecessarily

You use std::endl quite a lot. There are two purposes for std::endl: 1)print a newline, 2) flush the underlying output buffer. If you just want a new line, use '\n' instead.