| destructors-2a/point.cc - Implementation of class point - now with a destructor that deallocates the Point representation. | Lecture 4 - slide 12 : 40 Program 5 |
#include <cmath>
#include <iostream>
#include "point.h"
// Here we use the member initializer to establish the array of two doubles
Point::Point() : point_representation{new double[2]{0.0, 0.0}} {
}
Point::Point(double x_coord, double y_coord) : point_representation{new double[2]{x_coord, y_coord}}{
}
Point::~Point(){
std::cout << "Deleting point" << "(" << getx() << "," << gety() << ")" << std::endl;
delete[] point_representation;
}
double Point::getx () const{
return point_representation[0];
}
double Point::gety () const{
return point_representation[1];
}
std::ostream& operator<<(std::ostream& s, const Point& p){
return s << "(" << p.getx() << "," << p.gety() << ")" ;
}