Modern C++

@klmr

(CC0)

Don’t use f*cking pointers.

No, seriously.

int* pi = new int;
int i;
int* arr = new int[1024];
std::array<int, 1024> arr;
int* arr = new int[n];
std::vector<int> arr(n);
char* str = new char[1024]
std::string str;
void draw_shape(Shape const* shape);
draw_shape(new Rectangle);
void draw_shape(Shape const& shape);
draw_shape(Rectangle());
huge_object* build_new_object() {
  huge_object* ret = new huge_object;
  
  return ret;
}
huge_object build_new_object() {
  huge_object ret;
  
  return ret;
}
struct owner {
  resource* pr;
  owner() : pr(new resource) { }
  ~owner() { delete pr; }
};
struct owner {
  std::unique_ptr<resource> r;

  owner() : r(new resource) { }
};
struct owner {
  resource* pr;
  owner() : pr(new resource) { }
  ~owner() { delete pr; }
};
struct owner {
  std::shared_ptr<resource> r;

  owner() : r(make_shared()) {}
};

Pointers

must. not. own.

resources.

That’s it.