struct Buffer{
int* p;
unsigned n;
mutable std::string toString;
mutable bool toStringDirty;
Buffer (void); // implement it with correct initialization
Buffer (unsigned m, int val = 0); // inits with m ints with val
Buffer (const Buffer& a) {
Buffer::Buffer();
if (a.n) {
unsigned m = (n = a.n) * sizeof(int);
memcpy(p = (int*) malloc(m), a.p, m);
}
toString = a.toString;
toStringDirty = a.toStringDirty;
Buffer (const Buffer&&);
int& operator[](unsigned i);
const Buffer& operator=(const Buffer&&);
const Buffer& operator=(const Buffer&);
const Buffer& operator=(int val); //sets all with val
const Buffer operator+(const Buffer& a) const; // concatenates
// appends ‘a.first’ ints with an ‘a.second’ value
const Buffer operator+(const std::pair<unsigned,int>& a) const;
const Buffer operator-(unsigned m) const; // drops m ints at end
// converts to string with caching support, format as [%d] per integer
const std::string ToString (void) const;
};
I was given this struct to convert to a Buffer class. Any do's and dont's cuz this the first time ever i have encountered this problem? any advice would be appreciated. I know i have to use the right encapsulation as well as some move constructors. any advice? thank you.