diff --git a/src/api/c++/z3++.h b/src/api/c++/z3++.h index 02849ec3d..198f429a1 100644 --- a/src/api/c++/z3++.h +++ b/src/api/c++/z3++.h @@ -24,6 +24,7 @@ Notes: #include #include #include +#include #include #include #include @@ -392,21 +393,20 @@ namespace z3 { template class array { - T * m_array; + std::unique_ptr m_array; unsigned m_size; - array(array const & s); - array & operator=(array const & s); + array(array const & s) = delete; + array & operator=(array const & s) = delete; public: - array(unsigned sz):m_size(sz) { m_array = new T[sz]; } + array(unsigned sz):m_array(new T[sz]),m_size(sz) {} template array(ast_vector_tpl const & v); - ~array() { delete[] m_array; } - void resize(unsigned sz) { delete[] m_array; m_size = sz; m_array = new T[sz]; } + void resize(unsigned sz) { m_array.reset(new T[sz]); m_size = sz; } unsigned size() const { return m_size; } T & operator[](int i) { assert(0 <= i); assert(static_cast(i) < m_size); return m_array[i]; } T const & operator[](int i) const { assert(0 <= i); assert(static_cast(i) < m_size); return m_array[i]; } - T const * ptr() const { return m_array; } - T * ptr() { return m_array; } + T const * ptr() const { return m_array.get(); } + T * ptr() { return m_array.get(); } }; class object { @@ -1991,8 +1991,7 @@ namespace z3 { template template - array::array(ast_vector_tpl const & v) { - m_array = new T[v.size()]; + array::array(ast_vector_tpl const & v):m_array(new T[v.size()]) { m_size = v.size(); for (unsigned i = 0; i < m_size; i++) { m_array[i] = v[i];