Posts

Showing posts with the label operating-system

C++ programming: getting an error or not according to the computer in use.

C++ programming: getting an error or not according to the computer in use. Hello everyone, Here a code in c++ programming: #include <iostream> using namespace std; class Buffer { double* doubles; int size; public: Buffer(int size): size(size), doubles(new double[size]) { for (int i=0; i<size; ++i) doubles[i] = 0.0; } ~Buffer() { delete doubles; } void fill(double d) { Buffer newBuffer(size); for (int i=0; i<size; ++i) newBuffer.doubles [i] = d; this->doubles = newBuffer.doubles; } void print() const { for (int i=0; i<size; ++i) cout << doubles[i] << " "; cout << endl; } }; int main() { Buffer b1(5); b1.print(); Buffer b2(5); b2.fill(12.34); b2.print(); }` This code is not supposed to run without exception. Indeed, when my teacher run it (with his computer) he gets the next error: * Error in a.out: double free or corruption (fast...