I'm new programmer in C++
and I have some basic questions that I can't understand by looking online.
1) let's say I have an object that it's members are only primitives. in my program, I create the object using new. what should be in this object destructor ?
2) Now let's say I have list called lst
that contains some objects as the object above (only primitive members). if at some point I do the following:
lst[i] = new MyObject;
(when lst[i]
already has object in it).
should I delete the object that was in lst[i]
before this assignment? if not what actually happens?
here is part of my code to be more concrete:
class Point {
public:
Point();
~Point();
string toString() const;
void set(long int x, long int y);
Point(long int x, long int y);
long int getX() const;
long int getY() const;
// -----------operators--------------
bool operator==(const Point& point) const;
bool operator!=(const Point& point);
bool operator<(const Point& point);
private:
long int _x;
long int _y;
};
This is my PointSet class which hold list of points:
class PointSet
{
public:
PointSet();
PointSet(const PointSet &init);
~PointSet();
string toString() const;
bool add(const Point &point);
bool remove(const Point &point);
int getSize() const;
void setSize(int newSize);
bool operator==(const PointSet& other);
bool operator!=(const PointSet& other);
PointSet& operator-(const PointSet& other) const;
PointSet& operator&(const PointSet& other);
PointSet& operator=(const PointSet& other);
bool isMember(const Point& point) const;
Point* getPointsList();
private:
Point* _allPoints;
int _size;
int _capacity;
};
and this is the problem code in my main:
for(int i = 0; i < listLen; ++i)
{
pointsList[i] = pointsList[i + 1];
}
what will happen to the object in pointList[0]?? (pointsList is list of Point objects)