// BAD: missing destructor - memory leak #include typedef int T; class vector { public: explicit vector(size_t n = 0, T initial_value = 42) : size_(n), data_(new T[n]) { std::cerr << "constructor" << std::endl; for (size_t i = 0; i < n; ++i) data_[i] = initial_value; } #if 0 ~vector() { std::cerr << "destructor" << std::endl; delete[] data_; } #endif size_t size() const { return size_; } T *data() { return data_; } T operator[](size_t i) const { return data_[i]; } T *begin() { return data_; } T *end() { return data_ + size_; } private: size_t size_; T *data_; }; int main(void) { size_t n = 10; vector v(n); std::cout << v.size() << std::endl; for (T x : v) std::cout << x << std::endl; }