StrVec Class Definition

Having sketched the implementation, we can now define our StrVec class:

// simplified implementation of the memory allocation strategy for a vector-like class class StrVec { public:     StrVec(): // the allocator member is default initialized       elements(nullptr), first_free(nullptr), cap(nullptr) { }     StrVec(const StrVec&);            // copy constructor     StrVec &operator=(const StrVec&); // copy assignment     ~StrVec();                        // destructor     void push_back(const std::string&);  // copy the element     size_t size() const { return first_free - elements; }     size_t capacity() const { return cap - elements; }     std::string *begin() const { return elements; }     std::string *end() const ...

Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.