T
Tony Johansson
Hello!
I have these two class definitions below. Now to my question.
This text is from a book that I say must be wrong.
"The use of reference counters for the classes below brings up the question
of whether the assignment statement should be shallow or deep; in other
words, should you copy reference or values?
Given the interface below, it does not matter, because the state of Point
cannot be modified."
I mean it's a big difference if you do a deep copy which mean that in this
example the left side would get brand new Point object identical to the
right side.
But in the sentence above they say it doesn't matter but is that really
true.
//Tony
class Point
{
public:
point(double=0,double=0);
virtual ~Point();
double getX() const;
double getY() const;
private:
double x_;
double_;
};
class PointCounted
{
public:
PointCounted(double=0, double=0); // creates a point
PointCounted(const PointCounted&);
PointCounted(const Point&);
PointCounted& operator=(const PointCounted&);
~PointCounted();
double getX() const;
double getY() const;
private:
Point* p; //bridge to the implementetion
int *count_; //reference counter
};
I have these two class definitions below. Now to my question.
This text is from a book that I say must be wrong.
"The use of reference counters for the classes below brings up the question
of whether the assignment statement should be shallow or deep; in other
words, should you copy reference or values?
Given the interface below, it does not matter, because the state of Point
cannot be modified."
I mean it's a big difference if you do a deep copy which mean that in this
example the left side would get brand new Point object identical to the
right side.
But in the sentence above they say it doesn't matter but is that really
true.
//Tony
class Point
{
public:
point(double=0,double=0);
virtual ~Point();
double getX() const;
double getY() const;
private:
double x_;
double_;
};
class PointCounted
{
public:
PointCounted(double=0, double=0); // creates a point
PointCounted(const PointCounted&);
PointCounted(const Point&);
PointCounted& operator=(const PointCounted&);
~PointCounted();
double getX() const;
double getY() const;
private:
Point* p; //bridge to the implementetion
int *count_; //reference counter
};