3️⃣Buffer [18]
~Buffer() {
delete[] buffer; // Ensure proper deallocation in destructor
}
// Member functions to access and modify the buffer (consider bounds checking)
char getCharAt(int pos) const {
if (pos < 0 || pos >= size) {
throw std::out_of_range("Index out of bounds");
}
return buffer[pos];
}
void setCharAt(int pos, char value) const {
if (pos < 0 || pos >= size) {
throw std::out_of_range("Index out of bounds");
}
buffer[pos] = value;
}
int getSize() const { return size; }L’implementazione della classe Buffer fornita nell’esercizio è a rischio di memory leak in caso di problemi. Riscrivere la classe usando l’idioma RAII (Resource Acquistion Is Initialization), e mostrare come usare la classe. (6 punti)
Last updated